R: how to use command line arguments from R scripts

If you want to script R with arguments, you can type (under a Linux shell):

R --no-restore --no-save --args 10 < script.R

where –args is a list of arguments that you want to use in your script. This script will contain the following commands:

args <- commandArgs(trailingOnly=TRUE)

where trailingOnly means that commandArgs uses only the –args option so that you do not have to bother about the position of th –args argument.

Please follow and like us:
This entry was posted in Computer Science and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.