rocker-org / rocker-versioned

Run current & prior versions of R using docker
https://hub.docker.com/r/rocker/r-ver
GNU General Public License v2.0
297 stars 169 forks source link

R drops down to 3.1.1 after installing R package with apt-get #30

Closed dmenne closed 7 years ago

dmenne commented 7 years ago

With my Dockerfile:

https://github.com/dmenne/gastro-docker/blob/master/Dockerfile

I get R 3.4.0 with rocker/tidyverse:latest . When I add Shiny server (as stolen from your add_shiny.sh), the R version displayed by RStudio changes to 3.1.1. From docker bash, the displayed R version is 3.4.0, so it seems to be a problem with RStudio using the wrong R version.

3.4.0 is in /usr/local/bin/R Shiny servers installs 3.1.1 in /usr/bin/R, and RStudio uses this version. Other running packages correctly use 3.4,0; my packages require this version and run nicely.

... Simplified from https://github.com/rocker-org/rocker-versioned/blob/master/rstudio/add_shiny.sh

R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
dmenne commented 7 years ago

Setting the path to the R version in /etc/rstudio/rserver.conf (last line in code below) works for me. It is a bit surprising that this is necessary, because the docs say that which R is the R-version to be used, and this command returns the correct path to 3.4.0

# modified from https://github.com/rocker-org/rocker-versioned/blob/master/rstudio/add_shiny.sh
RUN wget --no-verbose https://download3.rstudio.org/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
  VERSION=$(cat version.txt)  && \
  wget --no-verbose "https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
  gdebi -n ss-latest.deb && \
  rm -f version.txt ss-latest.deb && \
  cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/ && \
  rm -rf /var/lib/apt/lists/* && \
  mkdir -p /var/log/shiny-server && \
  chown shiny.shiny /var/log/shiny-server && \
  mkdir -p /etc/services.d/shiny-server && \
  cd /etc/services.d/shiny-server && \
  echo '#!/bin/bash' > run && echo 'exec shiny-server' >> run && \
  chmod +x run && \
  echo 'rsession-which-r=/usr/local/bin/R' >> /etc/rstudio/rserver.conf  && \
  cd /
cboettig commented 7 years ago

Good catch, looks like the shiny binary is pulling in r-base from apt (apt doesn't know R is installed from source already). Ideally we could avoid or remove that after the fact (but probably don't want to be building shiny from source!)

Then there's the separate issue of Rstudio not obeying PATH priority, which sounds like an rstudio bug, but , looks like your workaround should let me fix that on our end. Thanks!

cboettig commented 7 years ago

Ah, it's not shiny that's pulling in r-base, but because you have installed an R package with apt-get (r-cran-rgl) that is causing you to end up with R-3.1.1. Apt-getting an R package will always pull in r-base (which is 3.1.1 on debian:jessie. For rocker/versioned stack we really recommend you install with install2.r / install.packages() which is configured to install from the appropriate CRAN snapshot. (yes, I realize that's a pain).

But I think we could still avoid the problem if we just add

  echo 'rsession-which-r=/usr/local/bin/R' >> /etc/rstudio/rserver.conf  && \

to the rstudio dockerfile here.

Guess we could also improve the documentation around this issue!

I'll also re-title this issue because it actually has nothing to do with shiny.

Thanks again for the bug report.

dmenne commented 7 years ago

I had stared at that line r-cran-rgl and knew something was fishy... But I remember in old times I had to pull rgl in like that, and could not do install2.r. Has it changed?

cboettig commented 7 years ago

@dmenne hasn't changed; a package like rgl will still need it's system dependencies installed, (I think libgl1-mesa-dev and libglu1-mesa-dev in this case, then install2.r should work) so yeah, apt-get install r-cran-rgl is certainly easier. apt-get install r-cran-rgl will increase your image size by a few hundred mgs I think since you'll have two versions of R, but probably not a big problem -- so I do think there's a valid use case here even though I hadn't initially considered it.

apt-get'ing a package will still give you a consistent version (since jessie is stable), but probably a much older version than you would get by using the MRAN archive for a recent version. Maybe not a problem for your use case. Also, not as many r packages in apt-get on jessie.

cboettig commented 7 years ago

One more footnote, once you are back into 3.4.0 with your fix, could you actually do library("rgl")? I would think you might have to fix your .libPaths() first too?

dmenne commented 7 years ago

"error: missing required header GL/gl.h"

Will have to check the paths (ok, forgot the glu1..). Trying again

dmenne commented 7 years ago

Thanks for your support: everything fine now. I don't have to adjust paths and take care of RStudio, because no R 3.1.1 is installed. With libgl1-mesa-dev and libglu1-mesa-dev in apt-get, I can simple install rgl which is required as dependency as some package.

https://github.com/dmenne/gastro-docker https://hub.docker.com/r/dmenne/gastro-docker/

So the take-home lesson: never install some r-xxx file with apt-get, otherwise the R-versions might get mixed up.

cboettig commented 7 years ago

Sounds good. Note this should only be a problem in rocker-versioned stack. apt-get should be great for rocker/shiny and rocker/r-base etc, (which also build on debian:testing and thus have much more up-to-date packages available via apt).