R 教材:批次方法 |
# File name: hello_1.r a <- c("Hello", "world", "!") print(a) b <- paste(a, collapse = " ") print(b) |
SHELL> R CMD BATCH --vanilla --slave hello_1.r output_file |
> a <- c("Hello", "world", "!") > print(a) [1] "Hello" "world" "!" > b <- paste(a, collapse = " ") > print(b) [1] "Hello world !" > |
SHELL> R --vanilla --slave < hello_1.r > output_file | |
or | |
SHELL> cat hello_1.r | R --vanilla --slave > output_file | |
or | |
SHELL> echo 'source("hello_1.r")' | R --vanilla --slave > output_file |
[1] "Hello" "world" "!" [1] "Hello world !" |
# File name: hello_2.r a <- c("Hello", "world,", argv, "!") print(a) b <- paste(a, collapse = " ") print(b) |
SHELL> echo 'argv <- "MOLAS"; source("hello_2.r")' | R --vanilla --slave > output_file |
[1] "Hello" "world," "MOLAS" "!" [1] "Hello world, MOLAS !" |
陳韋辰 (04/08/19) --- |