Args_test. The R code is as follows:
Args <-Commandargs ()
Cat ("args[1]=", args[1], "\ n")
Cat ("args[2]=", args[1], "\ n")
Cat ("args[3]=", args[3], "\ n")
Cat ("args[4]=", args[4], "\ n")
Cat ("args[5]=", args[5], "\ n")
Cat ("args[6]=", args[6], "\ n")
Cat ("args[7]=", args[7], "\ n")
Run as follows:
Rscript Args_test. R AAA BBB
The results are as follows:
args[1]=/usr/local/lib64/r/bin/exec/r
args[2]=/usr/local/lib64/r/bin/exec/r
args[3]=--no-restore
Args[4]=--file=args_test. R
args[5]=--args
args[6]= AAA
args[7]= BBB
Additional notes:
In Unix, outside of Windows need to call R script execution, and then need to enter a different parameter, similar to shell script command line parameter input, you can use the Rcript command implementation.
Command format: rscript [Options] [-e expression] file [args]
File represents the script that needs to be executed, and [options] [-e expression] can or may not be used.
[args] is a list of parameters.
First, you need to include the first line in the file:
Args <-Commandargs ()
Then execute in the following format
Rscript *. R parameter 1 Parameter 2 ...
In the file script, you can reference the parameter args,
args[1]= "/USR/LOCAL/LIB64/R/BIN/EXEC/R"
args[2]= "--slave"
args[3]= "--no-restore"
args[4]= "--FILE=A.R"
args[5]= "--args"
args[6]== parameter 1
args[7]== Parameter 2
The parameters of the visible input start with the sixth and seventh.
Ref:http://f.dataguru.cn/thread-174642-1-1.html
The R language uses command-line arguments