Modern R environments management in Datagrok with renv

As part of our work on supporting reproducible environments for scripting, we’ve recently added support for renv package manager in our R scripting. Now that’s possible to write such script:

#language: r
renv::init()
renv::install("hunspell@3.0.1")
library(hunspell)
correct <- hunspell_check("servise") # FALSE

The library in use (hunspell) isn’t available as part of the global Datagrok’s R packages set. Since R script is ran in Datagrok in an isolation from others, the local environment with hunspell introduced is guaranteed to only be active for this one script currently being run.

Renv-based package management is really convenient. Unlike in some other existing solutions, authors of the script introduce the desired environment with renv programmatically completely on the flight, while renv transparently fetches the dependencies from its global cache.

Though introducing renv hasn’t affected the time it takes to run one R script in Datagrok, we’ve discovered that renv approaches Internet servers when the dependency isn’t specified with a version. The check of the latest version may take some seconds by renv. We recommend to always specify a specific library version for renv.

Please find more on the feature here: https://datagrok.ai/help/develop/scripting#renv-environments.

2 Likes