Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using renv cache with rocker/rstudio #96

Closed
alsmnn opened this issue Nov 19, 2020 · 3 comments
Closed

Using renv cache with rocker/rstudio #96

alsmnn opened this issue Nov 19, 2020 · 3 comments
Labels

Comments

@alsmnn
Copy link

alsmnn commented Nov 19, 2020

Hello everybody,
I would like to use the renv-package with your rstudio images, more precisely I would like to use the renv cache folder of the host as the cache folder in the container.
There is the environment variable RENV_PATHS_CACHE, but I don't know the right place to mention it in the dockerfile.
Setting it via ENV RENV_PATHS_CACHE=/renv/cache in the dockerfile doesn't seem to pass through to Rstudio.
Can you guide me in the rigth direction?
Can I set it in ~/.Renviron in the container?

For further info see:
rstudio/renv#446

Stuff I already tried:

  • Manually setting Sys.setenv(RENV_PATHS_CACHE = "/renv/cache") inside the container. This works, but is a manual step I would like to remove.
  • Setting environment variable in dockerfile and create image -> environment variable isn't set in Rstudio.
  • Setting environment variable while calling docker run -> environment variable isn't set in Rstudio.
docker run -d --rm --name renv \
-e USERID=$UID \
-e PASSWORD=fake \
-e RENV_PATHS_CACHE=/renv/cache \
-v path/to/renv_cache/on_host:/renv/cache \
-v $(pwd):/work \
-p 8080:8787 my_rstudio_image:4.0.2

and the dockerfile of my_rstudio_image:4.0.2 looks like this:

FROM rocker/r-ver:4.0.2

LABEL org.label-schema.license="GPL-2.0" \
              org.label-schema.vcs-url="https://github.co/rocker-org/rocker-versioned" \
              org.label-schema.vendor="Rocker Project" \
              maintainer="Carl Boettiger <[email protected]>"

ENV S6_Version=v2.0.0.1
ENV RSTUDIO_VERSION=1.3.959
ENV RENV_PATHS_CACHE=/renv/cache

RUN /rocker_scripts/install_rstudio.sh
RUN /rocker_scripts/install_pandoc.sh
RUN /rocker_scripts/install_tidyverse.sh
RUN install2.r --error --skipinstalled -r $CRAN \
          	renv && rm -rf /tmp/downloaded_packages

EXPOSE 8787

CMD ["/init"]

Thanks for pointing me in the right direction.
Cheers

@alsmnn
Copy link
Author

alsmnn commented Nov 19, 2020

Setting it in ~/.Renvrion seems to do the trick.
The dockerfile looks like this now:

FROM rocker/r-ver:4.0.2

LABEL org.label-schema.license="GPL-2.0" \
              org.label-schema.vcs-url="https://github.co/rocker-org/rocker-versioned" \
              org.label-schema.vendor="Rocker Project" \
              maintainer="Carl Boettiger <[email protected]>"

ENV S6_Version=v2.0.0.1
ENV RSTUDIO_VERSION=1.3.959
ENV RENV_PATHS_CACHE=/renv/cache

RUN /rocker_scripts/install_rstudio.sh
RUN /rocker_scripts/install_pandoc.sh
RUN /rocker_scripts/install_tidyverse.sh
RUN install2.r --error --skipinstalled -r $CRAN \
          	renv && rm -rf /tmp/downloaded_packages && \
            echo 'RENV_PATHS_CACHE=/renv/cache' >> /home/rstudio/.Renviron

EXPOSE 8787

CMD ["/init"]

but is this the correct way of doing this?

@Pit-Storm
Copy link
Contributor

@alsmnn

I think this is realted to #170. Unfortunately the problem will resist, that you have to write an upstream (your own) Dockerfile, but you can use that one as a template and after you specified the ENV-Vars you want to use, you can dynamically change tham during startup. There will be no need to write different Dockerfiles for multiple different paths.

BTW: If you are using ~/.Renviron to set the renv cache it is not getting set if a .Rproject .Renviron file is loaded. Consider to set in in Renviron.site/Rprofile.site.

@eitsupi
Copy link
Member

eitsupi commented Apr 3, 2022

I close this as I believe it has been answered. Feel free to reopen it again if necessary.

@eitsupi eitsupi closed this as completed Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants