diff --git a/.github/workflows/style-and-lint.yaml b/.github/workflows/style-and-lint.yaml index 84a5f59b..c3485dc0 100644 --- a/.github/workflows/style-and-lint.yaml +++ b/.github/workflows/style-and-lint.yaml @@ -50,6 +50,7 @@ jobs: if: env.has_changes == 'true' run: | git add \*.R + git add \*.Rmd git commit -m 'Style via {styler}' - uses: r-lib/actions/pr-push@v2 diff --git a/DESCRIPTION b/DESCRIPTION index 110df5c2..79cf1382 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: rix -Title: Rix: Reproducible Environments with Nix +Title: Reproducible Data Science Environments with 'Nix' Version: 0.12.0 Authors@R: c( person("Bruno", "Rodrigues", , "bruno@brodrigues.co", role = c("aut", "cre"), @@ -11,8 +11,13 @@ Authors@R: c( person("Jacob", "Wujiciak-Jens", , "jacob@wujciak.de", role = "rev", comment = c(ORCID = "0000-0002-7281-3989", "Jacob reviewed the package (v. 0.9.1) for rOpenSci, see ")) ) -Description: Provides helper functions to create reproducible development - environments using the Nix package manager. +Description: Simplifies the creation of reproducible development environments + using the 'Nix' package manager. The included `rix()` function generates a + complete description of the development environment as a `default.nix` file, + which can then be built using `Nix'. This results in project specific + software environments with pinned versions of R, packages, linked system + dependencies, and other tools. Additional helpers make it easy to run R code + in 'Nix' software environments for testing and production. License: GPL (>= 3) URL: https://docs.ropensci.org/rix/ BugReports: https://github.com/ropensci/rix/issues diff --git a/R/included-datasets.R b/R/included-datasets.R index 94bd58de..a0be88ce 100644 --- a/R/included-datasets.R +++ b/R/included-datasets.R @@ -1,6 +1,6 @@ #' sysdata #' -#' Nix revisions with old R releases +#' 'Nix' revisions with old R releases #' #' @format A data frame with 39 rows and 3 variables: #' \describe{ @@ -8,5 +8,6 @@ #' \item{ revision }{ Nix revision containing this version of R } #' \item{ date }{ Date when this revision was available } #' } -#' @source Nix Package Version, by Marcelo Lazaroni +#' @source 'Nix' Package Version, by Marcelo Lazaroni +#' @noRd "available_r" diff --git a/R/nix_build.R b/R/nix_build.R index 39e40298..c2bb8ea1 100644 --- a/R/nix_build.R +++ b/R/nix_build.R @@ -1,7 +1,5 @@ #' Invoke shell command `nix-build` from an R session #' @param project_path Path to the folder where the `default.nix` file resides. -#' The default is `"."`, which is the working directory in the current R -#' session. #' @param message_type Character vector with messaging type, Either `"simple"` #' (default), `"quiet"` for no messaging, or `"verbose"`. #' @return integer of the process ID (PID) of `nix-build` shell command @@ -22,7 +20,7 @@ #' \dontrun{ #' nix_build() #' } -nix_build <- function(project_path = ".", +nix_build <- function(project_path = getwd(), message_type = c("simple", "quiet", "verbose")) { message_type <- match.arg(message_type, choices = c("simple", "quiet", "verbose") diff --git a/R/rix.R b/R/rix.R index 56f62357..a7b39cf8 100644 --- a/R/rix.R +++ b/R/rix.R @@ -34,32 +34,31 @@ #' 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. -#' @param project_path Character, defaults to the current working directory. -#' 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. +#' @param 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. #' @param overwrite Logical, defaults to FALSE. If TRUE, overwrite the #' `default.nix` file in the specified path. #' @param print Logical, defaults to FALSE. If TRUE, print `default.nix` to #' console. #' @param 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. +#' gives minimal but sufficient feedback. Other values are currently `"quiet`, +#' which generates the files without message, and `"verbose"`, displays all +#' the messages. #' @param shell_hook Character of length 1, defaults to `NULL`. Commands added -#' to the `shellHook` variable are executed when the Nix shell starts. So by -#' default, using `nix-shell default.nix` will start a specific program, -#' possibly with flags (separated by space), and/or do shell actions. You can -#' for example use `shell_hook = R`, if you want to directly enter the -#' declared Nix R session when dropping into the Nix shell. -#' @details This function will write a `default.nix` and an `.Rprofile` in the -#' chosen path. Using the Nix package manager, it is then possible to build a -#' reproducible development environment using the `nix-build` command in the -#' path. This environment will contain the chosen version of R and packages, -#' and will not interfere with any other installed version (via Nix or not) on -#' your machine. Every dependency, including both R package dependencies but -#' also system dependencies like compilers will get installed as well in that -#' environment. +#' to the `shellHook` variable are executed when the Nix shell starts. So by +#' default, using `nix-shell default.nix` will start a specific program, +#' possibly with flags (separated by space), and/or do shell actions. You can +#' for example use `shell_hook = R`, if you want to directly enter the declared +#' Nix R session when dropping into the Nix shell. @details This function will +#' write a `default.nix` and an `.Rprofile` in the chosen path. Using the Nix +#' package manager, it is then possible to build a reproducible development +#' environment using the `nix-build` command in the path. This environment will +#' contain the chosen version of R and packages, and will not interfere with any +#' other installed version (via Nix or not) on your machine. Every dependency, +#' including both R package dependencies but also system dependencies like +#' compilers will get installed as well in that environment. #' #' It is possible to use environments built with Nix interactively, either #' from the terminal, or using an interface such as RStudio. If you want to @@ -75,12 +74,12 @@ #' argument to `"other"`. We recommend reading the #' `vignette("e-interactive-use")` for more details. #' -#' Packages to install from Github or Gitlab must be provided in a list of 3 elements: -#' "package_name", "repo_url" and "commit". To install several packages, -#' provide a list of lists of these 3 elements, one per package to install. It -#' is also possible to install old versions of packages by specifying a -#' version. For example, to install the latest version of `{AER}` but an old -#' version of `{ggplot2}`, you could write: `r_pkgs = c("AER", +#' Packages to install from Github or Gitlab must be provided in a list of 3 +#' elements: "package_name", "repo_url" and "commit". To install several +#' packages, provide a list of lists of these 3 elements, one per package to +#' install. It is also possible to install old versions of packages by +#' specifying a version. For example, to install the latest version of `{AER}` +#' but an old version of `{ggplot2}`, you could write: `r_pkgs = c("AER", #' "ggplot2@2.2.1")`. Note however that doing this could result in dependency #' hell, because an older version of a package might need older versions of #' its dependencies, but other packages might need more recent versions of the @@ -89,10 +88,10 @@ #' the Nix revision closest to that date, by setting `r_ver = "3.1.0"`, which #' was the version of R current at the time. This ensures that Nix builds a #' completely coherent environment. For security purposes, users that wish to -#' install packages from Github/Gitlab or from the CRAN archives must provide a -#' security hash for each package. `{rix}` automatically precomputes this hash -#' for the source directory of R packages from GitHub/Gitlab or from the CRAN -#' archives, to make sure the expected trusted sources that match the +#' install packages from Github/Gitlab or from the CRAN archives must provide +#' a security hash for each package. `{rix}` automatically precomputes this +#' hash for the source directory of R packages from GitHub/Gitlab or from the +#' CRAN archives, to make sure the expected trusted sources that match the #' precomputed hashes in the `default.nix` are downloaded. If Nix is #' available, then the hash will be computed on the user's machine, however, #' if Nix is not available, then the hash gets computed on a server that we @@ -157,7 +156,7 @@ rix <- function(r_ver = "latest", local_r_pkgs = NULL, tex_pkgs = NULL, ide = c("other", "code", "radian", "rstudio", "rserver"), - project_path = ".", + project_path, overwrite = FALSE, print = FALSE, message_type = "simple", diff --git a/R/rix_init.R b/R/rix_init.R index 68d7e8e8..b8d6802a 100644 --- a/R/rix_init.R +++ b/R/rix_init.R @@ -62,8 +62,7 @@ #' it and set the `rprofile_action` to `"append"`. #' #' @param project_path Character with the folder path to the isolated nix-R -#' project. Defaults to `"."`, which is the current working directory path. If -#' the folder does not exist yet, it will be created. +#' project. If the folder does not exist yet, it will be created. #' @param rprofile_action Character. Action to take with `.Rprofile` file #' destined for `project_path` folder. Possible values include #' `"create_missing"`, which only writes `.Rprofile` if it does not yet exist @@ -94,7 +93,7 @@ #' message_type = c("simple") #' ) #' } -rix_init <- function(project_path = ".", +rix_init <- function(project_path, rprofile_action = c( "create_missing", "create_backup", "overwrite", "append" diff --git a/cran-comments.md b/cran-comments.md index 285410d2..7b86a1e1 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,57 @@ +## 23-09-2024 Resubmission + +### R CMD check results + +0 errors | 0 warnings | 1 note + +Note is because it's a new release. + +#### Comments from CRAN maintainers from submission of the 20-09-2024: + +- The Title field starts with the package name. Please omit it. + +Done. + +- Please always write package names, software names and API (application +programming interface) names in single quotes in title and description. +e.g: --> 'Nix' +Please note that package names are case sensitive. + +Done. + +- The Description field is intended to be a (one paragraph) description of +what the package does and why it may be useful. Please add more details +about the package functionality and implemented methods in your +Description text. + +Done. + +- If there are references describing the methods in your package, please +add these in the description field of your DESCRIPTION file in the form +authors (year) +authors (year, ISBN:...) +or if those are not available: +with no space after 'doi:', 'https:' and angle brackets for +auto-linking. (If you want to add a title as well please put it in +quotes: "Title") + +We added a reference to a paper describing Nix. + +- Please ensure that your functions do not write by default or in your +examples/vignettes/tests in the user's home filespace (including the +package directory and getwd()). This is not allowed by CRAN policies. +Please omit any default path in writing functions. In your +examples/vignettes/tests you can write to tempdir(). +-> R/rix.R; R/rix_init.R + +There was a vignette writing to `"."` instead of `tempdir()`, this has +been fixed with https://github.com/ropensci/rix/pull/328/commits/0f92911d6959b6f87cc4013744f2ede3c49d19d5 + +Regarding functions `rix()` and `rix_init()`: we don't set `project_path` to +`"."` by default anymore. + +* This is a new release. + ## R CMD check results 0 errors | 0 warnings | 1 note diff --git a/vignettes/z-advanced-topic-running-r-or-shell-code-in-nix-from-r.Rmd b/vignettes/z-advanced-topic-running-r-or-shell-code-in-nix-from-r.Rmd index da1cdc06..6a0bfd65 100644 --- a/vignettes/z-advanced-topic-running-r-or-shell-code-in-nix-from-r.Rmd +++ b/vignettes/z-advanced-topic-running-r-or-shell-code-in-nix-from-r.Rmd @@ -231,8 +231,7 @@ from. Accordingly, we define the R 4.2.0 environment in a *`env`*`_1_2_R-4-2-0`using Nix via `rix::rix()`. The latter environment will be the target environment where `df_as_vector()` will be evaluated in. - -```{r parsermd-chunk-11} +```{r, eval = F} library("rix") path_env_1_2 <- file.path(".", "_env_1_2_R-4-2-0") @@ -246,6 +245,23 @@ rix( list.files(path_env_1_2) ``` +```{r, include = F} +library("rix") + +path_env_1_2 <- file.path(tempdir(), "_env_1_2_R-4-2-0") + +rix( + r_ver = "4.2.0", + overwrite = TRUE, + project_path = path_env_1_2, + shell_hook = "R" +) +``` + +```{r, echo = F} +list.files(path_env_1_2) +``` + Now, initiate a new R session as development environment using `nix-shell`. Open a new terminal at the current working directory of your R session. The provided expression `default.nix`. defines R 4.1.3 in a "subfolder per subshell" @@ -327,8 +343,7 @@ compile!). Let's build a subshell with the latest version of R, but an older version of `{stringr}`: - -```{r parsermd-chunk-18} +```{r, eval = F} library("rix") path_env_stringr <- file.path(".", "_env_stringr_1.4.1") @@ -343,8 +358,21 @@ rix( list.files(path = path_env_stringr, all.files = TRUE) ``` -```{r, include = FALSE} -unlink(path_env_stringr, recursive = TRUE, force = TRUE) +```{r, include = F} +library("rix") + +path_env_stringr <- file.path(tempdir(), "_env_stringr_1.4.1") + +rix( + r_ver = "4.3.1", + r_pkgs = "stringr@1.4.1", + overwrite = TRUE, + project_path = path_env_stringr +) +``` + +```{r, echo = F} +list.files(path = path_env_stringr, all.files = TRUE) ``` We can now run the code in the subshell