Leila Lackey
2012-Jan-19 08:13 UTC
[R] Bash script produces: Error in library('package') : there is no package called 'package'
This is a follow-up to a post from 2007: https://stat.ethz.ch/pipermail/r-help/2007-April/129009.html Summary of the Problem: Packages are correctly installed and can be loaded when R is opened interactively or using a R script. However, a bash scripts produces an error similar to the following: #!/bin/bash ... R --no-save <<EOF ... library(package) Error in library(package) : there is no package called 'package' Execution halted At least two workable solutions exist but appear to apply in different circumstances. Solution found for the original post: Multiple versions of R; R (old): system wide R (new): on my user side only When I started R in the command prompt it was calling the R (new) version because of my .bashrc config. When I was scripting, I was opening a bash that was by passing some of my config file, thus I was running R (old), where scatterplot3d was NOT installed. To solve that I had to make sure I installed only one version of R system wide and then I had to install the package only once and could use it from any origin. To know if you have the same version problem you can save your output of R, from command and in a script, and look at the version number to see if they differ. You can also use> which Rboth from the terminal and a script to see if they differ. If above does not work or only one version of R is installed: Under some bash scripts, R appears to only look for packages in the R_LIBS_SITE location (/usr/lib/R/library in this instance), where base-packages are stored, and does not look for packages in the R_LIBS_USER location (/home/user/R/*library/2.14 in this instance), where user-installed packages are stored. Both locations are defined in Renviron. To work-around, packages can be copied from R_LIBS_SITE to R_LIBS_USER. Any thoughts or insights would be appreciated. Otherwise, I hope these work-arounds will be useful to others facing a similar error. Best, Leila [[alternative HTML version deleted]]
Petr Savicky
2012-Jan-19 11:11 UTC
[R] Bash script produces: Error in library('package') : there is no package called 'package'
On Thu, Jan 19, 2012 at 12:13:00AM -0800, Leila Lackey wrote:> This is a follow-up to a post from 2007: > https://stat.ethz.ch/pipermail/r-help/2007-April/129009.html > > Summary of the Problem: > > Packages are correctly installed and can be loaded when R is opened > interactively or using a R script. However, a bash scripts produces an > error similar to the following: > > #!/bin/bash > ... > R --no-save <<EOF > ... > library(package) > Error in library(package) : there is no package called 'package' > Execution halted > > > At least two workable solutions exist but appear to apply in different > circumstances. > > Solution found for the original post: > > Multiple versions of R; > R (old): system wide > R (new): on my user side only > > When I started R in the command prompt it was calling the R (new) version > because of my .bashrc config. When I was scripting, I was opening a bash > that was by passing some of my config file, thus I was running R (old), > where scatterplot3d was NOT installed. > > To solve that I had to make sure I installed only one version of R system > wide and then I had to install the package only once and could use it from > any origin.In a bash script, it is also possible to run R using a full path to its "R-version/bin/R". This path may possibly include $HOME, which should be the same in a bash script and in an interactive bash. In this case, the $PATH variable, which may differ, is not used.> To know if you have the same version problem you can save your output of R, > from command and in a script, and look at the version number to see if they > differ.In a situation, when the same version is installed in different directories, they may be distinguished by printing the variable .Library which prints the directory, where R is installed, with an additional "/library". Petr Savicky.
Seemingly Similar Threads
- R CMD check --as-cran attempts to hide R_LIBS_USER but fails
- R CMD check --as-cran attempts to hide R_LIBS_USER but fails
- R CMD check --as-cran attempts to hide R_LIBS_USER but fails
- Preventing $R_HOME/site-library/ via R_LIBS_SITE=":" (no other way?)
- Renviron settings for Linux Distributions: please tell me R Core's advice