renv2nix
Usage
renv2nix(
renv_lock_path = "renv.lock",
project_path,
return_rix_call = FALSE,
method = c("fast", "accurate"),
override_r_ver = NULL,
...
)Arguments
- renv_lock_path
Character, path of the renv.lock file, defaults to "renv.lock"
- project_path
Character, where to write
default.nix, for example "/home/path/to/project". The file will thus be written to the file "/home/path/to/project/default.nix". If the folder does not exist, it will be created.- return_rix_call
Logical, return the generated rix function call instead of evaluating it this is for debugging purposes, defaults to
FALSE- method
Character, the method of generating a nix environment from an renv.lock file. "fast" is an inexact conversion which simply extracts the R version and a list of all the packages in an renv.lock file and adds them to the
r_pkgsargument ofrix(). This will use a snapshot ofnixpkgsthat should contain package versions that are not too different from the ones defined in therenv.lockfile. For packages installed from GitHub or similar, an attempt is made to handle them and pass them to thegit_pkgsargument ofrix(). Currently defaults to "fast", "accurate" is not yet implemented.- override_r_ver
Character, defaults to NULL, override the R version defined in the
renv.lockfile with another version. This is especially useful if therenv.lockfile lists a version of R not (yet) available through Nix, or if the R version included in therenv.lockis too old compared to the package versions. Can also be a date, checkavailable_dates().- ...
Arguments passed on to
rixsystem_pkgsVector of characters. List further software you wish to install that are not R packages such as command line applications for example. You can look for available software on the NixOS website https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=
local_r_pkgsVector of characters, paths to local packages to install. These packages need to be in the
.tar.gzor.zipformats and must be in the same folder as the generated "default.nix" file.tex_pkgsVector of characters. A set of TeX packages to install. Use this if you need to compile
.texdocuments, or build PDF documents using Quarto. If you don't know which package to add, start by adding "amsmath". See thevignette("d2- installing-system-tools-and-texlive-packages-in-a-nix-environment")for more details.py_confList. A list containing two elements:
py_versionandpy_pkgs.py_versionshould be in the form"3.12"for Python 3.12, andpy_pkgsshould be an atomic vector of package names (e.g.,py_pkgs = c("polars", "plotnine", "great-tables")). If Python packages are requested but{reticulate}is not in the list of R packages, the user will be warned that they may want to add it. Whenpy_confpackages are requested, theRETICULATE_PYTHONenvironment variable is set to ensure the Nix environment does not use with a system-wide Python installation.jl_confList. A list of two elements,
jl_versionandjl_conf.jl_versionmust be of the form"1.10"for Julia 1.10. Leave empty or use an empty string to use the latest version, or use"lts"for the long term support version.jl_confmust be an atomic vector of packages names, for examplejl_conf = c("TidierData", "TidierPlots").ideCharacter, defaults to "none". If you wish to use RStudio to work interactively use "rstudio" or "rserver" for the server version. Use "code" for Visual Studio Code or "codium" for Codium, or "positron" for Positron. You can also use "radian", an interactive REPL. This will install a project-specific version of the chosen editor which will be differrent than the one already present in your system (if any). For other editors or if you want to use an editor already installed on your system (which will require some configuration to make it work seamlessly with Nix shells see the
vignette("e-configuring-ide")for configuration examples), use "none". Please be aware that VS Code and Positron are not free software. To facilitate their installation,rix()automatically enables a required setting without prompting the user for confirmation. See the "Details" section below for more information.overwriteLogical, defaults to FALSE. If TRUE, overwrite the
default.nixfile in the specified path.printLogical, defaults to FALSE. If TRUE, print
default.nixto console.message_typeCharacter. Message type, defaults to
"simple", which gives minimal but sufficient feedback. Other values are currently"quiet, which generates the files without message, and"verbose", displays all the messages.shell_hookCharacter of length 1, defaults to
NULL. Commands added to theshellHookvariable are executed when the Nix shell starts. So by default, usingnix-shell default.nixwill start a specific program, possibly with flags (separated by space), and/or do shell actions. You can for example useshell_hook = R, if you want to directly enter the declared Nix R session when dropping into the Nix shell.
Value
Nothing, this function is called for its side effects only, unless
return_rix_call = TRUE in which case an unevaluated call to rix() is
returned
Details
In order for this function to work properly, we recommend not
running it inside the same folder as an existing {renv} project. Instead,
run it from a new, empty directory which path you pass to project_path,
and use renv_lock_path to point to the renv.lock file in the original
{renv} folder. We recommend that you start from an empty folder to hold
your new Nix project, and copy the renv.lock file only (not any of the
other files and folders generated by {renv}) and then call renv2nix()
there. For more details, see vignette("f-renv2nix").
Examples
if (FALSE) { # \dontrun{
# if the lock file is in another folder
renv2nix(
renv_lock_path = "path/to/original/renv_project/renv.lock",
project_path = "path/to/rix_project"
)
# you could also copy the renv.lock file in the folder of the Nix
# project (don’t copy any other files generated by `{renv}`)
renv2nix(
renv_lock_path = "path/to/rix_project/renv.lock",
project_path = "path/to/rix_project"
)
} # }
