When using rpy2, the python implementation of R, I quickly came up with the issue of having missing packages (e.g., ggplot2)
With a fresh installation of rpy2 (and R-core), if you type the following code in your python shell:
from rpy2.robjects.packages import importr importr("ggplot2") |
You may have the following error message
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'ggplot2'
Error in .Primitive("as.environment")("package:ggplot2") :
no item called "package:ggplot2" on the search list
The solution is to install the missing package. This is not a Python package (so no use to try with easy_install). If you want to install a new R package, a compilation process will be required, so you must have install the R header files. For instance under Fedora,
sudo yum install R-devel |
Then, start R by typing “R” in a unix shell. R should start and prompt a command line where you just type:
install.packages(c("getopt","ggplot2"),dependencies=TRUE)
This command will download the relevant R packages, compile them and install them on your system. It may be longish depeding on the dependencies. Finally, restart your python shell and you should now be able to use the freshly installed packages.
3 Responses to Missing package in rpy2 (ggplot2)