parse.args {reader} | R Documentation |
Allows parameter specification by A=..., B=... in the command line e.g, R < myScript.R M=1 NAME=John X=10.5, using commandArgs()
parse.args(arg.list = NULL, coms = c("X"), def = 0, list.out = F, verbose = TRUE)
arg.list |
the result of a commandArgs() call, or else NULL to initiate this call within the function |
coms |
list of valid commands to look for, not case sensitive |
def |
list of default values for each parameter (in same order) |
list.out |
logical, whether to return output as a list or data.frame |
verbose |
logical, whether to print to the console which assignments are made and warning messages |
returns dataframe showing the resulting values [column 1, "value"] for each 'coms' (rownames); or, if list.out=TRUE, then returns a list with names corresponding to 'coms' and values equivalent to 'value' column of the data.frame that would be returned if list.out=FALSE
Nicholas Cooper nick.cooper@cimr.cam.ac.uk
parse.args(c("M=1","NAME=John","X=10.5"),coms=c("M","X","NAME")) parse.args(c("N=1")) # invalid command entered, ignored with warning temp.fn <- "tempScript1234.R" # make a temporary R Script file to call using the command line # not run # writeLines(c("require(reader)","parse.args(coms=c('M','X','NAME'))"),con=temp.fn) bash.cmd <- "R --no-save < tempScript1234.R M=1 NAME=John X=10.5" # run above command in the terminal, or using 'system' below: # not run # arg <- system(bash.cmd) # not run # unlink(temp.fn) # delete temporary file