I have a script that loads data, processes it, and saves the processed data out. I run it manually without a problem, but it does not work with Rscript. It uses the data.table package, and Rscript cannot find it. I have tried the solution here but get the following error message:
Error in eval(expr, envir, enclos) : could not find function ".getNamespace"
In addition: Warning message: package ‘data.table’ was built under R version 3.1.1 Error : unable to load R code in package ‘chron’
Error: package/namespace load failed for ‘data.table’
Execution halted
The script looks like:
#!/usr/local/bin/Rscript
args = commandArgs(trailingOnly = TRUE) # Take arguments from command line
library.path <- '/home/zack/R/x86_64-redhat-linux-gnu-library/3.1'
library('data.table', lib.loc = library.path)
That code is after failing with library(data.table). But I can load data.table fine, and so the rest of the script works, if I do this manually. The command I submit to bash is:
nohup /usr/local/bin/Rscript --vanilla <path to script> <args> &
Session info:
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
which Rscript:
/usr/local/bin/Rscript
/usr/local/bin/R loads data.table fine when it is called in an interactive session.