'Installing a R package in google colab
I am doing scientific research, and I am having some trouble using an R package to treat my data.
I program in python using Google Colab, and I don't know much about R neither how to import and run R packages in python.
So far, what I did was to adapt a suggestion found in other post as follows:
pip install rpy2
# Using R inside python
import rpy2
import rpy2.robjects.packages as rpackages
from rpy2.robjects.vectors import StrVector
from rpy2.robjects.packages import importr
utils = rpackages.importr('utils')
utils.chooseCRANmirror(ind=1)
# Install packages
packnames = ('zCompositions')
utils.install_packages(StrVector(packnames))
# Load packages
zCompositions = importr('zCompositions')
This is the error message I'm getting:
Don't know if it helps, but here is all I found on the package (zCompositions) which I'm trying to import and run.
Do you think it is possible to run this package in Google Colab?
Solution 1:[1]
The installation of the package seems to go well, but R does not know that it can load package from that directory. Try with specifying that directory when calling importr
.
Solution 2:[2]
In my case, the installation of rmpfr
, Bessel
and gmp
solved the issue. In collab it works as
!apt-get -qq install -y libgmp-dev
!apt-get install libmpfr-dev
!apt-get install bessel
Also, to be 100% sure it might be useful to install Bessel through R install.packages
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lgautier |
Solution 2 | Cornelius Roemer |