[R] [Rscript] difficulty passing named arguments from commandline

Ben Tupper btupper at bigelow.org
Fri Sep 7 04:38:31 CEST 2012


Hi Tom,

Using the script below I had no trouble. Here's an example 

Minke:R ben$ Rscript --no-init-file ./argCatcher.rs ./the=trouble .with=./args is=the.y argue
./the=trouble
.with=./args
is=the.y
argue


# script starts here
# argumentCatcher.rs
args = commandArgs(trailing = TRUE)
cat(args, sep = "\n")
q(runLast = FALSE, status = 0, save = "no") 
# script ends here

What does your R --version report?

Minke:R ben$ R --version
R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)


Cheers,
Ben






On Sep 6, 2012, at 7:27 PM, Tom Roche wrote:

> 
> Wanting a commandline solution (for a problem detailed @
> 
> http://mailman.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2012/msg00279.html
> 
> ) I turned to Rscript, and whacked out the q'n'd
> 
> https://github.com/TomRoche/GEIA_to_netCDF/blob/master/netCDF.stats.to.stdout.r
> 
> However it wasn't as quick as hoped, because I spent quite a bit of time
> figuring out how to pass the arguments. This works (note the quoting):
> 
> $ Rscript ./netCDF.stats.to.stdout.r 'netcdf.fp="./GEIA_N2O_oceanic.nc"' 'var.name="emi_n2o"'
>> For ./GEIA_N2O_oceanic.nc var=emi_n2o
>> 	cells=64800
>> 	obs=36143
>> 	min=5.96e-08
>> 	max=1.17e+03
>> 	mean=99.5
>> 	med=67.7
> 
> but this fails
> 
> roche at amad1:/project/inf14w/roche/GEIA_to_netCDF $ Rscript ./netCDF.stats.to.stdout.r 'netcdf.fp=./GEIA_N2O_oceanic.nc' 'var.name=emi_n2o'
>> Error in eval(expr, envir, enclos) : object '.' not found
>> Calls: eval -> eval
>> Execution halted
> 
> and this fails
> 
> roche at amad1:/project/inf14w/roche/GEIA_to_netCDF $ Rscript ./netCDF.stats.to.stdout.r netcdf.fp="GEIA_N2O_oceanic.nc" var.name="emi_n2o"
>> Error in eval(expr, envir, enclos) : 
>>  object 'GEIA_N2O_oceanic.nc' not found
>> Calls: eval -> eval
>> Execution halted
> 
> and this fails
> 
> roche at amad1:/project/inf14w/roche/GEIA_to_netCDF $ Rscript ./netCDF.stats.to.stdout.r netcdf.fp=./GEIA_N2O_oceanic.nc var.name=emi_n2o
>> Error in eval(expr, envir, enclos) : object '.' not found
>> Calls: eval -> eval
>> Execution halted
> 
> Must the quoting be so strict/brittle, or am I missing something?
> 
> Also, It Would Be Nice if there was more in the `help(Rscript)` examples
> about argument passing. I for one found the current examples quite terse
> and unhelpful.
> 
> TIA, Tom Roche <Tom_Roche at pobox.com>
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine   04575-0475 
http://www.bigelow.org




More information about the R-help mailing list