Docker - Rstudio - R old version running together - r

I'm working with docker since approximately a week and I don't understand some of the linking containers stuff.
I've downloaded from rocker, the latest images of Rstudio. It work nicely, everything is ok. I have one own made container with an old R version (let's say humm 3.1.0-1 for example). What I want to do is to use Rstudio from rocker with my own made R version. But this is where I don't understand. How it works ? Is it possible ? If I can do that that'll be awesome but I really don't understand how.
If someone have a solution, that'll be really great.
This is my dockerfile for my old R version :
#Get trusty version of ubuntu
FROM ubuntu:trusty
#We need to have https for cran
RUN apt-get -y update && apt-get -y install apt-transport-https
#We add the mirror directory to get older version packages
RUN echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list
#We clean and get authentication key
RUN apt-get clean && gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E084DAB9
#We add the key
RUN gpg -a --export E084DAB9 | apt-key add -
#We now update our lib
RUN apt-get -y update
# --> R PACKAGE INSTALLATION <--
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install r-base-core=3.1.0-1trusty0
RUN DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install r-doc-html=3.1.0-1trusty0
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install r-base-dev=3.1.0-1trusty0
#Check version
RUN R --version
I used : docker build -t r-basev3-1-0-1 . to build it and that works fine. It's just the link between rstudio and my container that I can't figure it out how to do it.
Thank's in advance,
Regards

I don't think it's possible (or easy) to link RStudio in one container to R in another container, as containers are supposed to be isolated from each other. The easiest thing to do is probably to build your own r-base image by modifying this file https://github.com/rocker-org/rocker/blob/master/r-base/Dockerfile (just need to change the version part I think) and then build your own rstudio image based on this customized image by modifying files in this folder https://github.com/rocker-org/rocker/tree/master/rstudio (change the FROM part to your own customized image).

Related

Using docker buildkit caching with R-packages

I'm trying to use the docker buildkit approach to caching packages to speed up adding packages to docker containers. I learned about it from the instructions for both python and apt-get packages and useful Stackexchange answer on caching python packages while building Docker. For Python and apt-get I am able to get this to work, but I can't get it to work for R packages.
In a Dockerfile for Python I'm able to change:
RUN pip install -r requirements.txt
to (and the comment looking bit at the top of the Dockerfile is needed)
# syntax=docker/dockerfile:experimental
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
And then when I add a package to the requirements.txt file, rather than re-downloading and building the packages, pip is able to re-use all the work it has done. So buildkit cache mounts add a level of caching beyond the image layers of docker. It's a massive timesaver. I'm hoping to set up something similar for r-packages.
Here is what I've tried that works for apt-get but not r-packges. I've also tried with the install2.r script.
# syntax=docker/dockerfile:experimental
FROM rocker/tidyverse
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
apt update && apt install -y gcc \
zsh \
vim
COPY ./requirements.R .
RUN --mount=type=cache,target=/usr/local/lib/R/site-library Rscript ./requirements.R
I think I don't understand:
How buildkit works. Does it do the building of containers inside a container? ie the cache path is on the 'build container'?
What one needs to specify as the target for R to notice that it already has downloaded (and possibly built).
I suspect that it has something to do with the keep.source command when installing an R package, as discussed in this question

How to upgrade IRKernel in Ubuntu?

On Ubuntu 18.04 LTS, while working R in JupyterNotebook (without Anaconda), the IRKernel is reading the R version 3.4. For using some packages like cowplot it is necessary to have at least version 3.5.
Basically, two steps should be taken:
Update R. These and that answers were a guideline.
Update IRKernel. The offical IRKernel instructions for Linux were useful.
Next, is described the complete procedure
1. Add Key to server
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
2. Add Entry to sources.list
echo 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' | sudo tee -a /etc/apt/sources.list
Depending on the linux you're using you should change, for example, bionic by xenial or cosmic, check out https://cran.r-project.org/bin/linux/ubuntu/README.html
3. Update Programs
According to the instructions in the above link, we should do the following:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev
4. Update /.local/share/jupyter/kernels/ir
type R in the console and follow the next steps according to this link
# In the console
R
# Inside R
install.packages(c('repr', 'IRdisplay', 'IRkernel'), type = 'source')
getRversion() # to verify the new R version
IRKernel::installspec()
This should show the following message:
[InstallKernelSpec] Removing existing kernelspec in /home/user_name/.local/share/jupyter/kernels/ir
[InstallKernelSpec] Installed kernelspec ir in /home/user_name/.local/share/jupyter/kernels/ir
As a final remark, you should remove the older version of R, which you can find in ~/R/x86_64-pc-linux-gnu-library, where you will now have two directories with two different versions or R (remove the older one).

How to install R 3.4.4 in alpine

I am trying to install R in my alpine image of docker. Earlier I did install it in my ubuntu image using
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 \
&& add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/' \
&& apt-get update \ && apt-get install -y r-base
Nowhere I could find how to install it in alpine.
Any help would be appreciated.
My base image is python:3.7-alpine
R is available in Alpine community repositories, so it's just a matter of installing the proper package:
apk add R
For a more compact image you could start off a vanilla Alpine image, such as alpine:3.9, if you don't need Python specifically.
The latest R version available on Alpine is 3.5.1. The closest to 3.4.4 is 3.4.2, which is available in Alpine V3.7. In that case, start off Alpine V3.7:
$ docker run -it alpine:3.7
/ # apk add R
If you need R version 3.4.4 exactly, you may have to build it from source. Fortunately, there is an excellent ready made Dockerfile by Artem Klevtsov which does just that:
https://github.com/artemklevtsov/r-alpine/blob/master/release/Dockerfile
Simply replace the R version string to 3.4.4 and build the image - works great.
Edit:
Another option for using a specific R version, which build is not available for native Alpine, is enabling glibc support on the Alpine container.
Normally, Alpine builds on musl libc, which is a specialized libc implementation that is generally not compatible to glibc, which is the de-facto standard libc used by most other Linux distributions. With glibc installed, you should be able to run any general-purpose R Linux build on the Alpine container.
The following Dockerfile portion would enable glibc support, adding some 10MB to the Alpine container size:
# Based on: https://github.com/anapsix/docker-alpine-java
FROM alpine:3.7
ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.28-r0
RUN set -ex && \
apk --update add libstdc++ curl ca-certificates && \
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk && \
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib

How to upgrade R in linux?

I am new to Linux. I am using Linux mint 18.1. I have installed R using system software manager. My current R version is 3.2. But I want to upgrade it to version 3.4.
How can I do it?
Note: I now keep on GitHub (here) an up-to-date guide to upgrading R on Linux Mint or Ubuntu Linux, which also includes a bit of extra information about system dependencies for tidyverse, the popular set of data-wrangling packages, as well as devtools, the popular R package development... package.
The link provided by FedRo is a good resource, however a slight change would need to be made since you're using Linux Mint 18.1 which uses Xenial repositories rather than Trusty repositories (see here). I also typically use the approach here to deal with packages I've already installed when I upgrade R rather than the approach offered by FedRo. So, for completeness, these are all the steps you'd need to take:
Step 1
Go to CRAN's list of mirrors and find the URL of the mirror that is closest to you. The terminal commands below assume you choose http://cran.wustl.edu/
Step 2
Open a terminal and enter the following commands1 (replacing http://cran.wustl.edu/ with whichever CRAN mirror URL you chose in step 1):
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo echo "deb http://cran.wustl.edu/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list
sudo apt update
sudo apt upgrade r-base r-base-dev
sudo apt update
sudo apt upgrade
Note also that I have put to upgrade r-base and r-base-dev, but I don't know if you have r-base-dev installed. If not, I highly recommend you install it via sudo apt install r-base-dev.
Step 3
Start a new R session and run the following:
update.packages(checkBuilt=TRUE, ask=FALSE)
Then you should be good to go.
Update: Linux Mint 19 and R 3.6.x
Since both Linux Mint and R have seen upgrades since I answered this question, I'm updating for those who come to this answer needing the info for Linux Mint 19 and R 3.6.x.
The only difference is that instead of the command
sudo echo "deb http://cran.wustl.edu/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list
you need to use
sudo echo "deb http://cran.wustl.edu/bin/linux/ubuntu bionic-cran35/" | sudo tee -a /etc/apt/sources.list
(replacing http://cran.wustl.edu/ with whichever CRAN mirror URL you chose in step 1)
1 I put here the full key, though many other guides you may see will use only the "short key."
I have updated this guide to use the full key out of security concerns (see here, for example).
Now it is very simple. Just make:
install.packages("ropenblas")
ropenblas::rcompiler()

R studio not working on ubuntu 16.04

I converted to Ubuntu today, but have a problems launching R studio. I installed R through the command prompt like this:
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/">> /etc/apt/sources.list'
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install r-base
I cheked if R was installed proper by typing R and then exiting by q(save="no").
I installed R studio through the command prompt by
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/rstudio-server-0.99.902-amd64.deb
sudo gdebi rstudio-server-0.99.902-amd64.deb
But this doesn't work and i can't find the launch button or open R studio.
Afterwards i tried to remove it and install it through the website but doesn't work either. What should i do?
There is no lauch button -- you connect to port 8787 on the machine running RStudio Server.
In other words, type http://localhost:8787 in the address bar of your browser. You should see a login screen with the RStudio logo. This connects you to your RStudio Server.
If you want to run the Desktop version you need to install the other available .deb package.
For those on Ubuntu 16.10, or who prefer to use the desktop version of RStudio, you may wish to follow the solution posted by Mike Williamson reproduced below:
1) Get the latest R Studio Daily Build here, though note that it's not necessarily stable.
2) Install, chaning the name of the package to the one you downloaded - perhaps easiest if you go to your Downloads directory - and you'll probably find that there are missing packages:
$ sudo dpkg -i rstudio-1.0.124-amd64.deb
3) Download the missing packages (the lack of which causes the installation to fail):
$ wget http://ftp.ca.debian.org/debian/pool/main/g/gstreamer0.10/libgstreamer0.10-0_0.10.36-1.5_amd64.deb
$ wget http://ftp.ca.debian.org/debian/pool/main/g/gst-plugins-base0.10/libgstreamer-plugins-base0.10-0_0.10.36-2_amd64.deb
4) Install them:
$ sudo dpkg -i libgstreamer0.10-0_0.10.36-1.5_amd64.deb
$ sudo dpkg -i libgstreamer-plugins-base0.10-0_0.10.36-2_amd64.deb
5) Make sure they don't get over-written at the next software update:
$ sudo apt-mark hold libgstreamer-plugins-base0.10-0
$ sudo apt-mark hold libgstreamer0.10
6) Install RStudio (changing name to the version you downloaded):
sudo gdebi rstudio-1.1.5-amd64.deb
7) Launch RStudio:
rstudio

Resources