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

Tom Roche Tom_Roche at pobox.com
Fri Sep 7 01:27:21 CEST 2012


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>



More information about the R-help mailing list