Adding R dependencies to your project

andrea.loweandrea.lowe Member, Moderator, Domino Posts: 25 mod

If you are working in R, an alternative to using Domino environments is to install packages into your project itself, so that the package installations persist between runs of your project. While this will be less performant than using a compute environment, it's easy to implement while developing projects. To do so, you should install packages to a subfolder inside your Domino project and tell R to look in that folder when it loads packages. E.g.,

dir.create("rlibs")
.libPaths("rlibs")
install.packages("some.package", dependencies=TRUE, repos='http://cran.us.r-project.org')

Then, in the scripts that you want to normally run (e.g. main.R), tell R to look in your rLibs directory if it can't find a package in the standard location, by using this command:

.libPaths(c(.libPaths(), "~/userLibrary"))

This way the packages will be loaded from the project dir without the need to install on every run.

Comments

  • mmironmmiron Member Posts: 10

    Thanks! Can you also provide an example in the domino documentation on how to install R packages in compute environments? I read through the documentation, but couldn't find an example. For those that aren't familiar with docker, this would be really helpful! Thanks!

  • katie.shakmankatie.shakman Administrator, Domino Posts: 165 admin
    edited March 3

    Hi @mmiron

    Good question! The example for adding R packages is in this video, at 5:20 in: https://docs.dominodatalab.com/en/4.1/reference/environments/Video_introduction_to_Domino_Environments.html

    It shows an example of installing the devtools package in the Dockerfile by adding this line:

    RUN R --no-save -e "library(devtools)"

    It would be great to have an R example in the text of our support docs, where it's easier to find, so we'll add that in. Thanks for the suggestion!

    Update:

    You can click the buttons for Install R Package or Install Python Package when editing your Dockerfile instructions, and these will generate a line with the correct syntax. See screenshot below.


    Katie

    Customer Success Engineer @ Domino

  • katie.shakmankatie.shakman Administrator, Domino Posts: 165 admin

    Update: The examples were added to this page https://docs.dominodatalab.com/en/4.1/reference/environments/Environment_management.html#managing-environments under Examples: Package Installation

    Katie

    Customer Success Engineer @ Domino

  • mmironmmiron Member Posts: 10

    Thanks Katie! I'm giving it a try now. Library("yourfavoritepackage") would load the library, but wouldn't you need to write the following for installing? Here I'm installing the lmerTest package.

    RUN R --no-save -e "install.packages('lmerTest')"

    Thanks!

  • katie.shakmankatie.shakman Administrator, Domino Posts: 165 admin
    edited March 3

    @mmiron Good catch! Yes you’re right on, I’ll update our example.

    If you're editing an environment, you can click the R Package button and it should give you the correct syntax, i.e.


    Katie

    Customer Success Engineer @ Domino

  • mmironmmiron Member Posts: 10

    Great, I didn't see that at first, and now I do. Thank you!

Sign In or Register to comment.