0

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:

enter image description here

Don't know if it helps, but here is all I found on the package (zCompositions) which I'm trying to import and run.

CRAN page

Documentation

Anaconda page

Github repo

Do you think it is possible to run this package in Google Colab?

  • 1
    It should be possible to install any package in colab. However, it is difficult to guess what is the source of your issue without details about the trouble encountered. The error message, and ideally a traceback coming with it, would be great. – lgautier Nov 07 '21 at 18:11
  • Sure! I edited the post and put it there! Thanks! – Eduardo Valentin dos Santos Nov 08 '21 at 14:37

2 Answers2

0

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.

lgautier
  • 11,363
  • 29
  • 42
0

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

Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
biba
  • 1