Home > Back-end >  Installing R packages on a GCE hosted google colab Jupyter notebook
Installing R packages on a GCE hosted google colab Jupyter notebook

Time:11-13

I am trying to install the calendR package on colab.

I am using the following:

install.packages("calendR")

library(calendR)

But this errors out with the following:

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

also installing the dependencies ‘magick’, ‘ggimage’


Warning message in install.packages("calendR"):
“installation of package ‘magick’ had non-zero exit status”
Warning message in install.packages("calendR"):
“installation of package ‘ggimage’ had non-zero exit status”
Warning message in install.packages("calendR"):
“installation of package ‘calendR’ had non-zero exit status”

Error in library(calendR): there is no package called ‘calendR’
Traceback:

1. library(calendR)

Anyone know how to install this?

CodePudding user response:

Default kernel

Google colab uses Python 3 Google Compute Engine backend based on docker container with ubuntu 18.04 by default. It is designed for python and has the ipython kernel. However, There is R installed as well. To install calendR, create and run a new cell with this content:

! add-apt-repository -y ppa:cran/imagemagick
! apt-get update
! apt-get install -y libmagick  -dev
! R -e "install.packages('calendR')"

This will execute IPython styled shell commands. Then you can do things like this in a new cell:

! R -e "library(calendR)"

IR kernel

Colab can be also host other kernels like ir for R. Then, the shell commands can be executed using R commands:

system("add-apt-repository -y ppa:cran/imagemagick")
system("apt-get update")
system("apt-get install -y libmagick  -dev")
install.packages("calendR")
library("calendR")
  • Related