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_pkgs
argument ofrix()
. This will use a snapshot ofnixpkgs
that should contain package versions that are not too different from the ones defined in therenv.lock
file. For packages installed from Github or similar, an attempt is made to handle them and pass them to thegit_pkgs
argument 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.lock
file with another version. This is especially useful if therenv.lock
file lists a version of R not (yet) available through Nix.- ...
Arguments passed on to
rix
system_pkgs
Vector 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= # nolint
local_r_pkgs
List. A list of local packages to install. These packages need to be in the
.tar.gz
or.zip
formats and must be in the same folder as the generated "default.nix" file.tex_pkgs
Vector of characters. A set of TeX packages to install. Use this if you need to compile
.tex
documents, or build PDF documents using Quarto. If you don't know which package to add, start by adding "amsmath". See the Vignette "Authoring LaTeX documents" for more details.ide
Character, defaults to "other". If you wish to use RStudio to work interactively use "rstudio" or "rserver" for the server version. Use "code" for Visual Studio Code. You can also use "radian", an interactive REPL. For other editors, use "other". This has been tested with RStudio, VS Code and Emacs. If other editors don't work, please open an issue.
overwrite
Logical, defaults to FALSE. If TRUE, overwrite the
default.nix
file in the specified path.print
Logical, defaults to FALSE. If TRUE, print
default.nix
to console.message_type
Character. 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_hook
Character of length 1, defaults to
NULL
. Commands added to theshellHook
variable are executed when the Nix shell starts. So by default, usingnix-shell default.nix
will 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. You can also 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. If
your project includes package with remote dependencies (for example, a
BioConductur package with a dependency on Github), renv2nix()
will not
generate a valid default.nix
file. The description of the issue and a
solution is given in the
vignette("z-advanced-topic-handling-packages-with-remote-dependencies")
.
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/original/rix_project/renv.lock",
project_path = "path/to/rix_project"
)
} # }