Rscript "there is no package" - r

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.

Related

Rscript not finding library

I have a problem when running R scripts on a Unix cluster as a batch job. The issue is when trying to load libraries in the environment, R cannot find the library. I'll give you an example. I'll use a basic R script names sess.R:
print(.libPaths())
library("gtools")
print(sessionInfo())
If I just run this script from the command line using the command:
$ Rscript sess.R
I get the following output:
[1] "/usr/lib64/R/library" "/usr/share/R/library"
R version 3.2.3 (2015-12-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.6 (Final)
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 base
other attached packages:
[1] gtools_3.5.0
The library "gtools" is correctly loaded, script is working. however if I write a simple batch job (I will include in the job a couple of optional parameters including an error and output file) like:
#!/bin/bash
#SBATCH --output=sess.out
#SBATCH --error=sess.err
Rscript sess.R
The job fails after a second. The two output files I get are of course sess.out and sess.err.
Sess.out contains the library directory:
[1] "/usr/lib64/R/library" "/usr/share/R/library"
which seem to be the same as when running Rscript from the command line, so no error there. However there is no printing of the Info Session since the script has been terminated. The sess.err file contains the following error:
Error in library("gtools") : there is no package called ‘gtools’
Execution halted
There, it seems like R cannot find gtools in this situation, even if the library path is the same...
Am I missing something? Is there an error I don't see somewhere? Or is it a problems of cluster settings?

stringi package won't install in CentOS

I am trying to install stringi package in R, but the installation never finishes. After the download and some compilation, I get the following message:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/marcus/R/x86_64-redhat-linux-gnu-library/3.3/stringi/libs/stringi.so':
/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/marcus/R/x86_64-redhat-linux-gnu-library/3.3/stringi/libs/stringi.so)
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/marcus/R/x86_64-redhat-linux-gnu-library/3.3/stringi’
The downloaded source packages are in
‘/tmp/RtmpT5KQVP/downloaded_packages’
Warning message:
In install.packages("stringi") :
installation of package ‘stringi’ had non-zero exit status
I searched the internet and I couldn't understand what this error message means. If it helps, this is my sessionInfo():
R version 3.3.1 (2016-06-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
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
loaded via a namespace (and not attached):
[1] tools_3.3.1
I solved my problem installing gcc 4.9.2. To do so, I ran
$ sudo yum install devtoolset-3-gcc-c++
$ sudo yum install devtoolset-3-gcc-gfortran
$ scl enable devtoolset-3 bash
in the shell. The first two commands install gcc and gfortran. The last one makes gcc 4.9.2 the standard compiler in the system. After that, I opened R and ran install.packages("stringi") to have my problem solved.

Why "solve" function produces segmentation fault with OpenStreetMap package in R?

I was using the spatsurv package in R and when compiling my code using R in the terminal on Debian GNU/Linux 8 (jessie), segmentation fault was returned and R was closed. After some debugging, I found out that the problem appears when using solve function. In addition, one of the authors of spatsurv package suggested me to test the same problem with each imported package. Then, after making that test, the problem was only with OpenStreetMap package.
library(OpenStreetMap)
x <- solve(diag(1, 1000))
# Segmentation fault
If I use the solve function before loading OpenStreetMap, I get the following:
x <- solve(diag(1, 1000))
library(OpenStreetMap)
x <- solve(diag(1, 1000))
# An irrecoverable stack overflow has occurred.
# Please check if any of your loaded .so files has enabled executable stack (see man page execstack(8))
# Error: segfault from C stack overflow
Information of my clean session is below:
R version 3.3.0 (2016-05-03)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
I would like to know how to solve this segmentation fault to be able to use spatsurv package.

Error while using rSymPy

I recently installed rSymPy to perform some symbolic calculations in R. This step also installed some dependencies (“rJava”, “rjson” and “rJython”). After the installation was complete, I loaded the library and ran a very simple command which gave me an error:
> library("rSymPy")
Loading required package: rJython
Loading required package: rJava
Loading required package: rjson
> x <- Var("x")
Error in .jcheck() : No running JVM detected. Maybe .jinit() would help.
Here is my sessionInfo(), just in case you need it:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)
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
other attached packages:
[1] rSymPy_0.2-1.1 rJython_0.0-4 rjson_0.2.15 rJava_0.9-8
loaded via a namespace (and not attached):
[1] tools_3.2.2 tcltk_3.2.2
I have tried to install different versions of required packages, but I always get this error. I would really appreciate any help.
Thanks,
Aashish
Thanks to Gabor Grothendieck (developer of rSymPy) for pointing out that sometimes one needs to manually initialize JVM. One can simply use "sympyStart()" at the beginning of the code, and that fixes the error.

Unable to compile PDF in R Studio (LaTeX Error: File `lmodern.sty' not found.)

I can't compile the most basic PDF file in R studio.
This is my error message:
output file: Report.knit.md
! LaTeX Error: File `lmodern.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name:
! Emergency stop.
<read *>
l.3 \usepackage
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
Execution halted
# > sessionInfo()
# R version 3.1.2 (2014-10-31)
# Platform: x86_64-unknown-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
#
# loaded via a namespace (and not attached):
# [1] digest_0.6.8 htmltools_0.2.6 rmarkdown_0.5.3.1 tools_3.1.2
# [5] yaml_2.1.13
As you are on an Ubuntu box:
edd#max:~$ locate lmodern.sty ## look for this file
/usr/share/texmf/tex/latex/lm/lmodern.sty
edd#max:~$ dpkg -S $(locate lmodern.sty) ## look for package with this file
lmodern: /usr/share/texmf/tex/latex/lm/lmodern.sty
edd#max:~$
indicating that you want to install the lmodern package:
sudo apt-get install lmodern
You can also search online at package.Ubuntu.com which also suggests the lmodern package.

Resources