command line arguments in bash to Rscript command line arguments in bash to Rscript bash bash

command line arguments in bash to Rscript


With the following in args.R

print(commandArgs(TRUE)[1])

and the following in args.sh

Rscript args.R 10

I get the following output from bash args.sh

[1] "10"

and no error. If necessary, convert to a numberic type using as.numeric(commandArgs(TRUE)[1]).


Just a guess, perhaps you need to convert CorrAns from character to numeric, since Value section of ?CommandArgs says:

A character vector containing the name of the executable and the user-supplied command line arguments.

UPDATE: It could be as easy as:

#!/bin/Rscriptargs <- commandArgs(TRUE)(CorrAns = args[1])(CorrAns = as.numeric(args[1]))


Reading the docs, it seems you might need to remove the TRUE from the call to commandArgs() as you don't call the script with --args. Either that, or you need to call Rscript Graphs.R --args 10.

Usage

commandArgs(trailingOnly = FALSE)

Arguments

trailingOnly logical. Should only arguments after --args be returned?