[R] Bash script produces: Error in library('package') : there is no package called 'package'

Petr Savicky savicky at cs.cas.cz
Thu Jan 19 12:11:43 CET 2012


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.



More information about the R-help mailing list