1

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.

Community
  • 1
  • 1
ZacharyST
  • 658
  • 2
  • 6
  • 22
  • Have you tried updating R and your R packages? Current version of R is 3.2.3. Generally I find that a simple update between mismatched packages/R version solves these kinds of issues. – black_sheep07 Feb 05 '16 at 21:13
  • do processes runs as same user? – jangorecki Feb 05 '16 at 21:29
  • I just updated to R 3.2.2 and reinstalled data.table. Do the processes run as the same user? I think so, in that I am logged on as myself both times, never run as sudo user. – ZacharyST Feb 05 '16 at 21:33
  • 3
    A possible reason is this: `--vanilla` does not read the user R profile and `.Renviron` file. If you have defined the path to your user library somewhere in these files, the R process started with `--vanilla` will not find the library and the packages installed in it. – Stibu Feb 05 '16 at 21:33
  • you can check user from R with `Sys.info()[c("user","effective_user")]` – jangorecki Feb 06 '16 at 00:32
  • @jangorecki, user and effective_user are the same. Stibu, removing --vanilla from the bash command leads to the same error. – ZacharyST Feb 09 '16 at 18:15
  • @ZacharyST debug by printing `.libPaths()` and `rownames(installed.packages(lib.loc = ...))` – jangorecki Mar 01 '16 at 18:56

0 Answers0