Skip to content
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
35 changes: 19 additions & 16 deletions R/rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@
#' 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
#' use RStudio, set the `ide` argument to `"rstudio"`. Please be aware that
#' RStudio is not available for macOS through Nix. As such, you may want to
#' use another editor on macOS. To use Visual Studio Code (or Codium), set the
#' `ide` argument to `"code"` or `"codium"` respectively, which will add the
#' `{languageserver}` R package to the list of R packages to be installed by
#' Nix in that environment. It is also possible to use Positron by setting the
#' `ide` argument to `"positron"`. Setting the `ide` argument to an editor
#' will install it from Nix, meaning that each of your projects can have a
#' dedicated IDE (or IDE version). `"radian"` and `"rserver"` are also
#' options.
#' for macOS, RStudio is only available starting from R version 4.4.3 or from
#' the 2025-02-28. As such, you may want to use another editor on macOS if you
#' need to use an environment with an older version of R. To use Visual Studio
#' Code (or Codium), set the `ide` argument to `"code"` or `"codium"`
#' respectively, which will add the `{languageserver}` R package to the list
#' of R packages to be installed by Nix in that environment. It is also
#' possible to use Positron by setting the `ide` argument to `"positron"`.
#' Setting the `ide` argument to an editor will install it from Nix, meaning
#' that each of your projects can have a dedicated IDE (or IDE version).
#' `"radian"` and `"rserver"` are also options.
#'
#' Instead of using Nix to install an IDE, you can also simply use the one you
#' have already installed on your system, with the exception of RStudio which
Expand Down Expand Up @@ -295,15 +296,17 @@ before continuing."
if (
message_type != "quiet" &&
Sys.info()["sysname"] == "Darwin" &&
ide == "rstudio"
ide == "rstudio" &&
((r_ver < "4.4.3" && is.null(date)) ||
(is.null(r_ver) && date < "2025-02-28"))
) {
warning(
"Your detected operating system is macOS, and you chose
'rstudio' as the IDE. Please note that 'rstudio' is not
available through 'nixpkgs' for macOS, so the expression you
generated will not build on macOS. If you wish to build this
expression on macOS, change the 'ide =' argument to either
'code' or 'none'. Please refer to the macOS-specific vignette
"Your operating system is detected as macOS, but you selected 'rstudio'
for an R version or date that does not support it.
To use RStudio on macOS, select at least R 4.4.3 or a
date on or after 2025-02-28. If you require an older R version or date,
choose a different IDE for compatibility.
Please refer to the macOS-specific vignette
https://docs.ropensci.org/rix/articles/b2-setting-up-and-using-rix-on-macos.html
for more details."
)
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/_snaps/rix/darwin_rstudio_default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

let
pkgs = import (fetchTarball "https://github.com/rstats-on-nix/nixpkgs/archive/2025-02-28.tar.gz") {};

rpkgs = builtins.attrValues {
inherit (pkgs.rPackages)
dplyr;
};

system_packages = builtins.attrValues {
inherit (pkgs)
R
glibcLocales
nix;
};

wrapped_pkgs = pkgs.rstudioWrapper.override {
packages = [ rpkgs ];
};

in

pkgs.mkShell {
LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else "";
LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
LC_TIME = "en_US.UTF-8";
LC_MONETARY = "en_US.UTF-8";
LC_PAPER = "en_US.UTF-8";
LC_MEASUREMENT = "en_US.UTF-8";

buildInputs = [ rpkgs system_packages wrapped_pkgs ];

}
2 changes: 0 additions & 2 deletions tests/testthat/test-ga_cachix.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
testthat::test_that("Snapshot test of ga_cachix()", {
skip_if(Sys.info()["sysname"] != "Linux")

testthat::announce_snapshot_file("ga_cachix/cachix_dev_env.yaml")

testthat::expect_snapshot_file(
path = ga_cachix(cache_name = "rstats-on-nix", path = "default.nix"),
name = "cachix_dev_env.yaml"
Expand Down
59 changes: 30 additions & 29 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ testthat::test_that("rix(), ide is 'rstudio', Linux", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/rstudio_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "rstudio", path_default_nix),
name = "rstudio_default.nix",
Expand Down Expand Up @@ -110,8 +108,6 @@ testthat::test_that("rix(), ide is 'none' or 'code'", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/other_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
ide = "none",
Expand All @@ -120,8 +116,6 @@ testthat::test_that("rix(), ide is 'none' or 'code'", {
name = "other_default.nix"
)

testthat::announce_snapshot_file("rix/code_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
ide = "code",
Expand All @@ -130,8 +124,6 @@ testthat::test_that("rix(), ide is 'none' or 'code'", {
name = "code_default.nix"
)

testthat::announce_snapshot_file("rix/codium_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
ide = "codium",
Expand All @@ -140,8 +132,6 @@ testthat::test_that("rix(), ide is 'none' or 'code'", {
name = "codium_default.nix"
)

testthat::announce_snapshot_file("rix/positron_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
ide = "positron",
Expand Down Expand Up @@ -184,8 +174,6 @@ testthat::test_that("Quarto gets added to sys packages", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/no_quarto_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
pkgs = "dplyr",
Expand All @@ -195,8 +183,6 @@ testthat::test_that("Quarto gets added to sys packages", {
name = "no_quarto_default.nix",
)

testthat::announce_snapshot_file("rix/yes_quarto_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(
pkgs = c("dplyr", "quarto", "data.table"),
Expand All @@ -212,7 +198,7 @@ testthat::test_that("Quarto gets added to sys packages", {
)
})

testthat::test_that("If on darwin and ide = rstudio, raise warning", {
testthat::test_that("If on darwin and ide = rstudio, raise warning for old R", {
os_type <- Sys.info()["sysname"]
skip_if(os_type != "Darwin" || os_type == "Windows")

Expand Down Expand Up @@ -241,6 +227,35 @@ testthat::test_that("If on darwin and ide = rstudio, raise warning", {
)
})

testthat::test_that("If on darwin and ide = rstudio, work for R 4.4.3", {
os_type <- Sys.info()["sysname"]
skip_if(os_type != "Darwin" || os_type == "Windows")

path_default_nix <- normalizePath(tempdir())
on.exit(
unlink(path_default_nix, recursive = TRUE, force = TRUE),
add = TRUE
)

save_default_nix_test <- function(path_default_nix) {
rix(
date = "2025-02-28",
ide = "rstudio",
r_pkgs = "dplyr",
project_path = path_default_nix,
overwrite = TRUE,
shell_hook = NULL
)

file.path(path_default_nix, "default.nix")
}

testthat::expect_snapshot_file(
path = save_default_nix_test(path_default_nix),
name = "darwin_rstudio_default.nix",
)
})

testthat::test_that("If on ide = rstudio, but no R packages, raise error", {
path_default_nix <- tempdir()
on.exit(
Expand Down Expand Up @@ -318,8 +333,6 @@ testthat::test_that("rix(), date working", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/date_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "none", path_default_nix),
name = "date_default.nix",
Expand Down Expand Up @@ -379,8 +392,6 @@ testthat::test_that("rix(), bleeding-edge", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/bleeding-edge_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "none", path_default_nix),
name = "bleeding-edge_default.nix",
Expand Down Expand Up @@ -445,8 +456,6 @@ testthat::test_that("rix(), frozen-edge", {
file.path(path_default_nix, "/default.nix")
}

testthat::announce_snapshot_file("rix/frozen-edge_default.nix")

frozen_edge_commit <- get_right_commit("frozen-edge")

system(
Expand Down Expand Up @@ -519,8 +528,6 @@ testthat::test_that("rix(), only one GitHub package", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/one_git_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(path_default_nix),
name = "one_git_default.nix",
Expand Down Expand Up @@ -662,8 +669,6 @@ testthat::test_that("rix(), bioc-devel", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/bioc-devel_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "none", path_default_nix),
name = "bioc-devel_default.nix",
Expand Down Expand Up @@ -708,8 +713,6 @@ testthat::test_that("rix(), r-devel", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/r-devel_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "none", path_default_nix),
name = "r-devel_default.nix",
Expand Down Expand Up @@ -754,8 +757,6 @@ testthat::test_that("rix(), r-devel-bioc-devel", {
file.path(path_default_nix, "default.nix")
}

testthat::announce_snapshot_file("rix/r-devel-bioc-devel_default.nix")

testthat::expect_snapshot_file(
path = save_default_nix_test(ide = "none", path_default_nix),
name = "r-devel-bioc-devel_default.nix",
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-rix_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ testthat::test_that("Snapshot test of rix_init(), create_missing, empty file", {
rprofile_file
}

testthat::announce_snapshot_file("find_rev/golden_Rprofile.txt")

rprofile_con <- file(rprofile_file, open = "wb", encoding = "native.enc")
on.exit(close(rprofile_con), add = TRUE)

Expand Down Expand Up @@ -105,7 +103,8 @@ testthat::test_that("Snapshot test of rix_init(), append", {
rprofile_file <- paste0(path_env_nix, "/.Rprofile")
rprofile_con <- file(rprofile_file, open = "a+", encoding = "native.enc")

writeLines(enc2utf8("This is in the original Rprofile"),
writeLines(
enc2utf8("This is in the original Rprofile"),
rprofile_con,
useBytes = TRUE
)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-tar_nix_ga.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
testthat::test_that("Snapshot test of tar_nix_ga()", {
testthat::announce_snapshot_file("tar_nix_ga/run-pipeline.yaml")

testthat::expect_snapshot_file(
path = tar_nix_ga(),
name = "run-pipeline.yaml"
Expand Down
28 changes: 15 additions & 13 deletions vignettes/b2-setting-up-and-using-rix-on-macos.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -165,35 +165,37 @@ Nix path) appear on the R library path.

### RStudio and other development interfaces on macOS

As of writing, RStudio cannot be installed through `nixpkgs` for macOS, and if
you wish to use RStudio with a Nix environment, you have to install it through
`nixpkgs`. This means that it is impossible to use RStudio and a Nix environment
on macOS. When you try to generate an expression with `ide =
"rstudio"` on macOS, this will raise a warning. Here are the options you have:

RStudio installed via traditional means cannot be used with Nix shells. To use
RStudio, you must install it through Nix. As of now, RStudio in `nixpkgs` for
macOS is only available for R 4.4.3 or later, or for dates on or after
2025-02-28. Using RStudio with a Nix environment for older R versions or dates
is not possible, you will need to choose a different IDE, or no IDE. If you
attempt to generate an expression with `ide = "rstudio"` on macOS for R versions
older than 4.4.3 or dates before 2025-02-28, a warning will be raised. Your
options are:

- set `r_ver = 4.4.3` or pick a date on or after the 2025-02-28 if you don't need
to run an older version of R;
- ignore the warning, because the environment will be built on a Linux
distribution (even though you generated the expression on macOS) and used on a
Linux distribution;
- change the `ide =` argument to either `"other"` or `"code"` or `"positron"`.
- change the `ide =` argument to either `"none"` or `"code"` or `"positron"`.
Use `"code"` if you want to use VS Code and `"other"` for any other editor,
like Vim or Emacs. These other editors don't need to be installed through
`nixpkgs` to use Nix environments, unlike RStudio. See the
`nixpkgs` to use Nix environments, unlike RStudio. See the
`vignette("e-configure-ide")` for more details;
- if you're working on a pipeline with the `{targets}` package, you could run it
on GitHub Actions. This means you could work on the code on RStudio outside
of the Nix environment, as the code will only be executed on GitHub Actions
of the Nix environment, as the code will only be executed on GitHub Actions
runners. See this vignette
`vignette("z-advanced-topic-reproducible-analytical-pipelines-with-nix")` for
further details;
- work on your project as usual, using your usual installation of R and RStudio,
but generate a `default.nix` at the end with `ide = "none"` with the right
version of R for reproducibility purposes;
- use *subshells* to execute only the code you need to run in a specific
environment. See this vignette
environment. See this vignette
`vignette("z-advanced-topic-running-r-or-shell-code-in-nix-from-r")`;
- help us package RStudio for macOS on `nixpgs`. See
[here](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/rstudio/default.nix),
the Nix expression for RStudio.

We recommend you continue with the next vignette before tackling the more
advanced topics listed above: `vignette("c-using-rix-to-build-project-specific-environments")`.
Expand Down
Loading
Loading