Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch rix() with shell_hook = NULL default, Nix-R wrappers nix_build() and with_nix(); update testfiles #127

Merged
merged 8 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/tests-r-via-system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 13 additions & 8 deletions R/rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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")))

Expand Down
3 changes: 2 additions & 1 deletion dev/flat_nix_build.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 18 additions & 10 deletions dev/flat_rix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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")))

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
20 changes: 9 additions & 11 deletions dev/flat_with_nix.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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", {
Expand All @@ -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(
Expand All @@ -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)
Expand Down
49 changes: 32 additions & 17 deletions inst/extdata/default.nix
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 ];

}
21 changes: 13 additions & 8 deletions man/rix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/code_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ let
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ git_archive_pkgs rpkgs tex system_packages ];
shellHook = "R --vanilla";

}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/no_quarto_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ let
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ rpkgs system_packages ];
shellHook = "R --vanilla";

}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/other_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ let
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ git_archive_pkgs rpkgs tex system_packages ];
shellHook = "R --vanilla";

}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/rstudio_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ let
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ git_archive_pkgs rpkgs tex system_packages rstudio_pkgs ];
shellHook = "R --vanilla";

}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rix/yes_quarto_default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ let
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ rpkgs system_packages ];
shellHook = "R --vanilla";

}
3 changes: 2 additions & 1 deletion tests/testthat/test-nix_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
Loading
Loading