The R language uses command-line arguments

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.