diff --git a/.github/workflows/tests-r-via-system.yaml b/.github/workflows/tests-r-via-system.yaml index 55e375f2..58c16de7 100644 --- a/.github/workflows/tests-r-via-system.yaml +++ b/.github/workflows/tests-r-via-system.yaml @@ -28,13 +28,16 @@ jobs: - name: Install R packages uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::devtools, any::codetools + extra-packages: any::devtools, any::codetools any::covr - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - name: devtools::test() via system R run: Rscript -e 'devtools::test()' + + - name: covr::codecov() via system R + run: RScript -e 'covr::codecov(quiet = FALSE, clean = FALSE, install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")) - name: Show testthat output run: | diff --git a/DESCRIPTION b/DESCRIPTION index 9fac4778..59f5ace0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,4 +31,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/R/rix.R b/R/rix.R index 311743c3..e3ba02e3 100644 --- a/R/rix.R +++ b/R/rix.R @@ -18,15 +18,19 @@ #' interactively use "rstudio" or "code" for Visual Studio Code. 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". +#' @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". #' @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 shell_hook Character, defaults to `"R --vanilla"`. Commands added to the shell_hook get -#' executed when the Nix shell starts (via `shellHook`). So by default, using `nix-shell default.nix` will -#' start R. Set to NULL if you want bash to be started instead. +#' @param shell_hook Character of length 1, defaults to `NULL`. Commands added +#' to the `shellHook` variable executed when the Nix shell starts. So +#' by default, using `nix-shell default.nix` (or path with `shell.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. #' @details This function will write a `default.nix` 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 @@ -74,7 +78,8 @@ #' ide = "code", #' project_path = path_default_nix, #' overwrite = TRUE, -#' print = TRUE) +#' print = TRUE, +#' shell_hook = NULL) #' } rix <- function(r_ver = "latest", r_pkgs = NULL, @@ -85,7 +90,7 @@ rix <- function(r_ver = "latest", project_path = ".", overwrite = FALSE, print = FALSE, - shell_hook = "R --vanilla"){ + shell_hook = NULL){ stopifnot("'ide' has to be one of 'other', 'rstudio' or 'code'" = (ide %in% c("other", "rstudio", "code"))) diff --git a/dev/flat_nix_build.Rmd b/dev/flat_nix_build.Rmd index b0d35cce..fec8d0fa 100644 --- a/dev/flat_nix_build.Rmd +++ b/dev/flat_nix_build.Rmd @@ -241,7 +241,8 @@ testthat::test_that("Testing that `nix_build()` builds derivation", { rix( r_ver = "latest", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) out <- nix_build( diff --git a/dev/flat_rix.Rmd b/dev/flat_rix.Rmd index b14d58a6..b1c5aeba 100644 --- a/dev/flat_rix.Rmd +++ b/dev/flat_rix.Rmd @@ -34,15 +34,19 @@ you use another IDE, you can leave the "ide" argument blank: #' interactively use "rstudio" or "code" for Visual Studio Code. 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". +#' @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". #' @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 shell_hook Character, defaults to `"R --vanilla"`. Commands added to the shell_hook get -#' executed when the Nix shell starts (via `shellHook`). So by default, using `nix-shell default.nix` will -#' start R. Set to NULL if you want bash to be started instead. +#' @param shell_hook Character of length 1, defaults to `NULL`. Commands added +#' to the `shellHook` variable executed when the Nix shell starts. So +#' by default, using `nix-shell default.nix` (or path with `shell.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. #' @details This function will write a `default.nix` 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 @@ -90,7 +94,8 @@ you use another IDE, you can leave the "ide" argument blank: #' ide = "code", #' project_path = path_default_nix, #' overwrite = TRUE, -#' print = TRUE) +#' print = TRUE, +#' shell_hook = NULL) #' } rix <- function(r_ver = "latest", r_pkgs = NULL, @@ -101,7 +106,7 @@ rix <- function(r_ver = "latest", project_path = ".", overwrite = FALSE, print = FALSE, - shell_hook = "R --vanilla"){ + shell_hook = NULL){ stopifnot("'ide' has to be one of 'other', 'rstudio' or 'code'" = (ide %in% c("other", "rstudio", "code"))) @@ -409,7 +414,8 @@ testthat::test_that("Snapshot test of rix()", { ), ide = ide, project_path = path_default_nix, - overwrite = TRUE) + overwrite = TRUE, + shell_hook = NULL) paste0(path_default_nix, "/default.nix") @@ -454,7 +460,9 @@ testthat::test_that("Quarto gets added to sys packages", { r_pkgs = pkgs, ide = "other", project_path = path_default_nix, - overwrite = TRUE) + overwrite = TRUE, + shell_hook = NULL + ) paste0(path_default_nix, "/default.nix") diff --git a/dev/flat_with_nix.Rmd b/dev/flat_with_nix.Rmd index 90d8489d..84d3dd14 100644 --- a/dev/flat_with_nix.Rmd +++ b/dev/flat_with_nix.Rmd @@ -890,8 +890,6 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { # R version 3.5.3 on Nixpkgs does not build for aarch64-darwin (ARM macOS) skip_if(Sys.info()["sysname"] == "Darwin") - skip_on_covr() - path_subshell <- tempdir() rix_init( @@ -903,7 +901,8 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { rix( r_ver = "3.5.3", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) out_subshell <- with_nix( @@ -919,12 +918,12 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { message_type = "simple" ) - # On a recent version of R, set.seed(1234);sample(seq(1,10), 5) - # returns c(10, 6, 5, 4, 1) - # but not on versions prior to 3.6 + # On a recent version of R, set.seed(1234);sample(seq(1,10), 5) + # returns c(10, 6, 5, 4, 1) + # but not on versions prior to 3.6 testthat::expect_true( - all(c(2, 6, 5, 8, 9) == out_subshell) - ) + all(c(2, 6, 5, 8, 9) == out_subshell) + ) }) testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { @@ -936,8 +935,6 @@ testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { skip_if_not(nix_shell_available()) - skip_on_covr() - path_subshell <- tempdir() rix_init( @@ -949,7 +946,8 @@ testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { rix( r_ver = "4.2.0", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) df <- data.frame(a = 1:3, b = 4:6) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index ed6b84ac..a7d9088b 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,34 +1,49 @@ -# This file was generated by the {rix} R package v0.5.1.9000 on 2024-01-29 +# This file was generated by the {rix} R package v0.5.1.9000 on 2024-02-02 # with following call: -# >rix(r_ver = "902d74314fae5eb824bc7b597bd4d39640345557", -# > r_pkgs = NULL, -# > system_pkgs = NULL, +# >rix(r_ver = "94b122adfc90316feaea838f29aa3f2e3de2b203", +# > r_pkgs = c("dplyr", +# > "AER@1.2-8"), +# > system_pkgs = c("quarto"), # > git_pkgs = list(package_name = "rix", # > repo_url = "https://github.com/b-rodrigues/rix/", # > branch_name = "master", -# > commit = "11f6898fde38a4793a7f53900c88d2fd930e882f"), +# > commit = "da581f90273cb1ccfedbe18808097bf33b84d63c"), # > ide = "other", # > project_path = "inst/extdata", -# > overwrite = TRUE) -# It uses nixpkgs' revision 902d74314fae5eb824bc7b597bd4d39640345557 for reproducibility purposes -# which will install R version latest +# > overwrite = TRUE, +# > print = TRUE, +# > shell_hook = NULL) +# It uses nixpkgs' revision 94b122adfc90316feaea838f29aa3f2e3de2b203 for reproducibility purposes +# which will install R as it was as of nixpkgs revision: 94b122adfc90316feaea838f29aa3f2e3de2b203 # Report any issues to https://github.com/b-rodrigues/rix let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/902d74314fae5eb824bc7b597bd4d39640345557.tar.gz") {}; - git_archive_pkgs = [(pkgs.rPackages.buildRPackage { + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/94b122adfc90316feaea838f29aa3f2e3de2b203.tar.gz") {}; + rpkgs = builtins.attrValues { + inherit (pkgs.rPackages) dplyr; +}; + git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { url = "https://github.com/b-rodrigues/rix/"; branchName = "master"; - rev = "11f6898fde38a4793a7f53900c88d2fd930e882f"; - sha256 = "sha256-8Svbdu2qySZRfcXmf6PcqdtSJoHI2t9nC2XUUS9KuRo="; + rev = "da581f90273cb1ccfedbe18808097bf33b84d63c"; + sha256 = "sha256-eDAxkXSrX+Q5TWwzkwMDG5rB8VXFKaLJLLKEJEvxjeo="; + }; + propagatedBuildInputs = builtins.attrValues { + inherit (pkgs.rPackages) httr jsonlite sys; + }; + }) (pkgs.rPackages.buildRPackage { + name = "AER"; + src = pkgs.fetchzip { + url = "https://cran.r-project.org/src/contrib/Archive/AER/AER_1.2-8.tar.gz"; + sha256 = "sha256-OqxXcnUX/2C6wfD5fuNayc8OU+mstI3tt4eBVGQZ2S0="; }; propagatedBuildInputs = builtins.attrValues { - inherit (pkgs.rPackages) codetools httr jsonlite sys; + inherit (pkgs.rPackages) car lmtest sandwich survival zoo Formula; }; - }) ]; + })]; system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales nix ; + inherit (pkgs) R glibcLocales nix quarto; }; in pkgs.mkShell { @@ -40,6 +55,6 @@ let LC_PAPER = "en_US.UTF-8"; LC_MEASUREMENT = "en_US.UTF-8"; - buildInputs = [ git_archive_pkgs system_packages ]; - shellHook = "R --vanilla"; + buildInputs = [ git_archive_pkgs rpkgs system_packages ]; + } diff --git a/man/rix.Rd b/man/rix.Rd index 582372b6..18e13b9b 100644 --- a/man/rix.Rd +++ b/man/rix.Rd @@ -14,7 +14,7 @@ rix( project_path = ".", overwrite = FALSE, print = FALSE, - shell_hook = "R --vanilla" + shell_hook = NULL ) } \arguments{ @@ -37,18 +37,22 @@ interactively use "rstudio" or "code" for Visual Studio Code. 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.} -\item{project_path}{Character, defaults to the current working directory. Where to write -\code{default.nix}, for example "/home/path/to/project". -The file will thus be written to the file "/home/path/to/project/default.nix".} +\item{project_path}{Character, defaults to the current working directory. +Where to write \code{default.nix}, for example "/home/path/to/project". +The file will thus be written to the file +"/home/path/to/project/default.nix".} \item{overwrite}{Logical, defaults to FALSE. If TRUE, overwrite the \code{default.nix} file in the specified path.} \item{print}{Logical, defaults to FALSE. If TRUE, print \code{default.nix} to console.} -\item{shell_hook}{Character, defaults to \code{"R --vanilla"}. Commands added to the shell_hook get -executed when the Nix shell starts (via \code{shellHook}). So by default, using \verb{nix-shell default.nix} will -start R. Set to NULL if you want bash to be started instead.} +\item{shell_hook}{Character of length 1, defaults to \code{NULL}. Commands added +to the \code{shellHook} variable executed when the Nix shell starts. So +by default, using \verb{nix-shell default.nix} (or path with \code{shell.nix}) will +start a specific program, possibly with flags (separated by space), and/or +do shell actions. You can for example use \code{shell_hook = R}, if you want to +directly enter the declared Nix R session.} } \value{ Nothing, this function only has the side-effect of writing a file @@ -107,6 +111,7 @@ rix(r_ver = "latest", ide = "code", project_path = path_default_nix, overwrite = TRUE, - print = TRUE) + print = TRUE, + shell_hook = NULL) } } diff --git a/tests/testthat/_snaps/rix/code_default.nix b/tests/testthat/_snaps/rix/code_default.nix index 65111b74..e46898f0 100644 --- a/tests/testthat/_snaps/rix/code_default.nix +++ b/tests/testthat/_snaps/rix/code_default.nix @@ -54,5 +54,5 @@ let LC_MEASUREMENT = "en_US.UTF-8"; buildInputs = [ git_archive_pkgs rpkgs tex system_packages ]; - shellHook = "R --vanilla"; + } diff --git a/tests/testthat/_snaps/rix/no_quarto_default.nix b/tests/testthat/_snaps/rix/no_quarto_default.nix index 1ba16870..b74393e6 100644 --- a/tests/testthat/_snaps/rix/no_quarto_default.nix +++ b/tests/testthat/_snaps/rix/no_quarto_default.nix @@ -18,5 +18,5 @@ let LC_MEASUREMENT = "en_US.UTF-8"; buildInputs = [ rpkgs system_packages ]; - shellHook = "R --vanilla"; + } diff --git a/tests/testthat/_snaps/rix/other_default.nix b/tests/testthat/_snaps/rix/other_default.nix index e2154ee5..eaab8726 100644 --- a/tests/testthat/_snaps/rix/other_default.nix +++ b/tests/testthat/_snaps/rix/other_default.nix @@ -54,5 +54,5 @@ let LC_MEASUREMENT = "en_US.UTF-8"; buildInputs = [ git_archive_pkgs rpkgs tex system_packages ]; - shellHook = "R --vanilla"; + } diff --git a/tests/testthat/_snaps/rix/rstudio_default.nix b/tests/testthat/_snaps/rix/rstudio_default.nix index 167ad560..26adfcb6 100644 --- a/tests/testthat/_snaps/rix/rstudio_default.nix +++ b/tests/testthat/_snaps/rix/rstudio_default.nix @@ -57,5 +57,5 @@ let LC_MEASUREMENT = "en_US.UTF-8"; buildInputs = [ git_archive_pkgs rpkgs tex system_packages rstudio_pkgs ]; - shellHook = "R --vanilla"; + } diff --git a/tests/testthat/_snaps/rix/yes_quarto_default.nix b/tests/testthat/_snaps/rix/yes_quarto_default.nix index 1e4ffafa..89ec0bef 100644 --- a/tests/testthat/_snaps/rix/yes_quarto_default.nix +++ b/tests/testthat/_snaps/rix/yes_quarto_default.nix @@ -18,5 +18,5 @@ let LC_MEASUREMENT = "en_US.UTF-8"; buildInputs = [ rpkgs system_packages ]; - shellHook = "R --vanilla"; + } diff --git a/tests/testthat/test-nix_build.R b/tests/testthat/test-nix_build.R index d4d56076..4d54e667 100644 --- a/tests/testthat/test-nix_build.R +++ b/tests/testthat/test-nix_build.R @@ -23,7 +23,8 @@ testthat::test_that("Testing that `nix_build()` builds derivation", { rix( r_ver = "latest", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) out <- nix_build( diff --git a/tests/testthat/test-rix.R b/tests/testthat/test-rix.R index 9fb98a55..4eddd4ea 100644 --- a/tests/testthat/test-rix.R +++ b/tests/testthat/test-rix.R @@ -21,7 +21,8 @@ testthat::test_that("Snapshot test of rix()", { ), ide = ide, project_path = path_default_nix, - overwrite = TRUE) + overwrite = TRUE, + shell_hook = NULL) paste0(path_default_nix, "/default.nix") @@ -64,7 +65,9 @@ testthat::test_that("Quarto gets added to sys packages", { r_pkgs = pkgs, ide = "other", project_path = path_default_nix, - overwrite = TRUE) + overwrite = TRUE, + shell_hook = NULL + ) paste0(path_default_nix, "/default.nix") diff --git a/tests/testthat/test-with_nix.R b/tests/testthat/test-with_nix.R index d4cfe3f2..833c3600 100644 --- a/tests/testthat/test-with_nix.R +++ b/tests/testthat/test-with_nix.R @@ -11,8 +11,6 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { # R version 3.5.3 on Nixpkgs does not build for aarch64-darwin (ARM macOS) skip_if(Sys.info()["sysname"] == "Darwin") - skip_on_covr() - path_subshell <- tempdir() rix_init( @@ -24,7 +22,8 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { rix( r_ver = "3.5.3", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) out_subshell <- with_nix( @@ -40,12 +39,12 @@ testthat::test_that("Testing `with_nix()` if Nix is installed", { message_type = "simple" ) - # On a recent version of R, set.seed(1234);sample(seq(1,10), 5) - # returns c(10, 6, 5, 4, 1) - # but not on versions prior to 3.6 + # On a recent version of R, set.seed(1234);sample(seq(1,10), 5) + # returns c(10, 6, 5, 4, 1) + # but not on versions prior to 3.6 testthat::expect_true( - all(c(2, 6, 5, 8, 9) == out_subshell) - ) + all(c(2, 6, 5, 8, 9) == out_subshell) + ) }) testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { @@ -57,8 +56,6 @@ testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { skip_if_not(nix_shell_available()) - skip_on_covr() - path_subshell <- tempdir() rix_init( @@ -70,7 +67,8 @@ testthat::test_that("Test `with_nix()` if Nix is installed on R 4.2.0", { rix( r_ver = "4.2.0", overwrite = TRUE, - project_path = path_subshell + project_path = path_subshell, + shell_hook = NULL ) df <- data.frame(a = 1:3, b = 4:6)