Skip to content

Commit

Permalink
check pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Rodrigues committed Jan 24, 2024
1 parent d3e258e commit fc14898
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 76 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Description: Provides helper functions to create reproducible development
License: GPL (>= 3)
URL: https://b-rodrigues.github.io/rix/
BugReports: https://github.com/b-rodrigues/rix
Depends:
R (>= 2.10)
Imports:
codetools,
httr,
Expand All @@ -26,5 +28,6 @@ VignetteBuilder:
knitr
Config/fusen/version: 0.5.2
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
2 changes: 1 addition & 1 deletion dev/0-dev_history.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fusen::inflate(flat_file = "dev/flat_save_r_nix_revs.Rmd",

```{r}
local({
knitr::knit("vignettes/save-the-nix-package-versions-data.Rmd",
knitr::knit("vignettes/developers-vignette-save-the-nix-package-versions-data.Rmd",
output = tempfile())
usethis::use_data(r_nix_revs,
overwrite = TRUE)
Expand Down
2 changes: 2 additions & 0 deletions dev/4a-install_r_pkgs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ It is possible to install an arbitrary version of a package that has been
archived on CRAN:

```{r}
path_default_nix <- tempdir()
rix(r_ver = "4.2.1",
r_pkgs = c("dplyr@0.8.0", "janitor@1.0.0"),
system_pkgs = NULL,
Expand Down
2 changes: 1 addition & 1 deletion vignettes/1-getting-started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ time read through the vignettes and you should be fine.
For example:


```{r parsermd-chunk-1, eval = FALSE}
```{r eval = FALSE}
rix(r_ver = "latest",
r_pkgs = c("dplyr", "chronicler"),
ide = "other")
Expand Down
12 changes: 6 additions & 6 deletions vignettes/2a-setting-up-and-using-rix-on-linux-and-windows.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ Systems](https://determinate.systems/posts/determinate-nix-installer), a company
that provides services and tools built on Nix. Simply open a terminal and run
the following line (on Windows, if you cannot or have decided not to activate
systemd, then you have to append `--init none` to the command. You can find more
details about this on [The Determinante Nix
details about this on [The Determinate Nix
Installer page](https://github.com/DeterminateSystems/nix-installer)):


```{sh parsermd-chunk-1, eval = FALSE}
```{sh eval = FALSE}
curl --proto '=https' --tlsv1.2 -sSf \
-L https://install.determinate.systems/nix | \
sh -s -- install
Expand Down Expand Up @@ -148,8 +148,8 @@ rix(r_ver = "latest",
to generate a `default.nix`, and then use that file to generate an environment
with R, `{dplyr}` and `{ggplot2}`. If you need to add packages for your project,
rerun the command above, but add the needed packages to `r_pkgs`. This is
detailled in the vignette `vignette("4a-install_r_pkgs")` and
`vignette("4b-install_sys_pkgs")`.
detailled in the vignette `vignette("4a-installing-r-packages-in-a-nix-environment")` and
`vignette("4b-installing-system-tools-and-texlive-packages-in-a-nix-environment")`.


## Generating expressions
Expand All @@ -163,11 +163,11 @@ Start an R session, and install `{rix}` if that's not already done. Because
r-universe:


```{r parsermd-chunk-2, eval = FALSE}
```{r eval = FALSE}
install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev",
"https://cloud.r-project.org"))
```

You can then use the `{rix}` package to generate expressions. Consult the
next vignette `vignette("3-building_envs_with_rix")` to learn more.
next vignette `vignette("3-using-rix-to-build-project-specific-environments")` to learn more.

19 changes: 10 additions & 9 deletions vignettes/2b-setting-up-and-using-rix-on-macos.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ library(rix)
<!-- WARNING - This vignette is generated by {fusen} from dev/2b-macos.Rmd: do not edit by hand -->

*This vignette will discuss macOS-specific topics. If you're not using macOS, you
can ignore this vignette, and read the [Setting up and using rix on Linux and Windows]()
can ignore this vignette, and read the
`vignette("2a-setting-up-and-using-rix-on-linux-and-windows")`
vignette instead.*


Expand All @@ -46,7 +47,7 @@ that provides services and tools built on Nix. Simply open a terminal and run th
line:


```{sh parsermd-chunk-1, eval = FALSE}
```{sh eval = FALSE}
curl --proto '=https' --tlsv1.2 -sSf \
-L https://install.determinate.systems/nix | \
sh -s -- install
Expand Down Expand Up @@ -84,8 +85,8 @@ rix(r_ver = "latest",
to generate a `default.nix`, and then use that file to generate an environment
with R, `{dplyr}` and `{ggplot2}`. If you need to add packages for your project,
rerun the command above, but add the needed packages to `r_pkgs`. This is
detailled in the vignette `vignette("4a-install_r_pkgs")` and
`vignette("4b-install_sys_pkgs")`.
detailled in the vignette `vignette("4a-installing-r-packages-in-a-nix-environment")` and
`vignette("4b-installing-system-tools-and-texlive-packages-in-a-nix-environment")`.


## Generating expressions
Expand All @@ -99,13 +100,13 @@ R session, and install `{rix}` if that's not already done. Because `{rix}` is
not yet on CRAN, the easiest way is to install it from its r-universe:


```{r parsermd-chunk-2, eval = FALSE}
```{r eval = FALSE}
install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev",
"https://cloud.r-project.org"))
```

You can then use the `{rix}` package to generate expressions. Consult the
next vignette `vignette("3-building_envs_with_rix")` to learn more.
next vignette `vignette("3-using-rix-to-build-project-specific-environments")` to learn more.


## More macOS specificities
Expand Down Expand Up @@ -139,16 +140,16 @@ on macOS. When you try to generate an expression with `ide =
- 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 runners. See this
vignette `vignette("raps_with_nix")` for further details;
vignette `vignette("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 = "other"` 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 `vignette("subshells")`;
environment. See this vignette `vignette("advanced-topic-running-r-or-shell-code-in-nix-from-r")`;
- help us package RStudio for macOS on `nixpgs`. See
[https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/rstudio/default.nix](the
expression for RStudio).

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

22 changes: 12 additions & 10 deletions vignettes/3-using-rix-to-build-project-specific-environments.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ With the `rix::rix()` function, you can easily generate the right `default.nix`
file. You need to provide the following inputs to `rix()`:

- `r_ver`: the version of R required. Use "latest" for the latest version;
- `r_pkgs`: the required R packages. For example "dplyr" (more on this in the vignette `vignette("4a-install_r_pkgs")`);
- `system_pkgs`: the required system packages, if needed. For example "quarto", or a Python interpreter (more on this in the vignette `vignette("4b-install_sys_pkgs")`);
- `git_pkgs`: list of git packages to add (more on this in the vignette `vignette("4a-install_r_pkgs")`);
- `r_pkgs`: the required R packages. For example "dplyr" (more on this in the vignette `vignette("4a-installing-r-packages-in-a-nix-environment")`);
- `system_pkgs`: the required system packages, if needed. For example "quarto", or a Python interpreter (more on this in the vignette `vignette("4b-installing-system-tools-and-texlive-packages-in-a-nix-environment")`);
- `git_pkgs`: list of git packages to add (more on this in the vignette `vignette("4a-installing-r-packages-in-a-nix-environment")`);
- `ide`: the integrated development editor to use (more on this in the vignette `vignette("5-interactive_use")`)
- `path`: the path where to save the `default.nix` file.
- `overwrite`: whether to overwrite the `default.nix` file or not.
Expand All @@ -45,7 +45,7 @@ file. You need to provide the following inputs to `rix()`:
Run the following command to generate the right `default.nix` file:


```{r parsermd-chunk-1}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "latest",
Expand All @@ -72,7 +72,7 @@ file. This file is a symlink to the software installed by Nix. `{rix}` also
provides a `nix_build()` function to build Nix environments from within an
interactive R session, but it is not always guaranteed to succeed, due to
differences in platforms. This is explained in more detail in the following
vignette `vignette("subshells")`. In case of doubt, run `nix-build` from your
vignette `vignette("advanced-topic-running-r-or-shell-code-in-nix-from-r")`. In case of doubt, run `nix-build` from your
usual terminal application.

To now use the environment, type in the same terminal as before:
Expand All @@ -94,7 +94,7 @@ an environment with R version 4.2.1, the `{dplyr}` and `{janitor}` packages and
no specific IDE:


```{r parsermd-chunk-2}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "4.2.1",
Expand All @@ -110,7 +110,7 @@ rix(r_ver = "4.2.1",
The file looks like this:


```{r parsermd-chunk-3, echo = F}
```{r echo = F}
cat(readLines(paste0(path_default_nix, "/default.nix")), sep = "\n")
```

Expand All @@ -123,8 +123,9 @@ as well. This means that R versions and package versions are always coupled when
using Nix. However, if you need a specific version of R, but also a specific
version of a package that is not available in that particular Nix revision, one
solution is to install that package from Github or fro the CRAN archives. Read
the vignette `vignette("4a-install_r_pkgs")` to know more about this. To know
which versions of R are available, read the documention of `available_r()`.
the vignette `vignette("4a-installing-r-packages-in-a-nix-environment")` to know
more about this. To know which versions of R are available, read the documention
of `available_r()`.


## Running programs from an environment
Expand All @@ -151,7 +152,8 @@ cd /absolute/path/to/housing/ && nix-shell default.nix --run "Rscript -e 'target

It is also possible to run single functions in an isolated environment from an
active R session using `with_nix()` and get the output of that function loaded
into the current session. Refer to this vignette `vignette("subshells")` for
into the current session. Refer to this vignette
`vignette("advanced-topic-running-r-or-shell-code-in-nix-from-r")` for
more details on how to achieve this. Concretely this means that you could be
running R version 4.3.2 (installed via Nix, or not), and execute a function on R
version 4.0.0 for example in a subshell (or execute a function that requires an
Expand Down
22 changes: 13 additions & 9 deletions vignettes/4a-installing-r-packages-in-a-nix-environment.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ It is possible to install an arbitrary version of a package that has been
archived on CRAN:


```{r parsermd-chunk-1}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "4.2.1",
r_pkgs = c("dplyr@0.8.0", "janitor@1.0.0"),
system_pkgs = NULL,
Expand All @@ -43,7 +45,7 @@ rix(r_ver = "4.2.1",
overwrite = TRUE)
```

```{r parsermd-chunk-2, echo = F}
```{r echo = F}
cat(readLines(paste0(path_default_nix, "/default.nix")), sep = "\n")
```

Expand All @@ -62,7 +64,7 @@ particular package.
It is also possible to install packages from Github:


```{r parsermd-chunk-3}
```{r}
rix(r_ver = "4.2.1",
r_pkgs = c("dplyr", "janitor"),
git_pkgs = list(
Expand All @@ -81,7 +83,7 @@ rix(r_ver = "4.2.1",
```

```{r parsermd-chunk-4, echo = F}
```{r echo = F}
cat(readLines(paste0(path_default_nix, "/default.nix")), sep = "\n")
```

Expand All @@ -97,7 +99,7 @@ This example shows how to install packages from CRAN, from the CRAN archives and
from GitHub:


```{r parsermd-chunk-5}
```{r}
rix(r_ver = "4.2.1",
r_pkgs = c("dplyr", "janitor", "AER@1.2-8"),
git_pkgs = list(
Expand All @@ -116,11 +118,13 @@ rix(r_ver = "4.2.1",
```

```{r parsermd-chunk-6, echo = F}
```{r echo = F}
cat(readLines(paste0(path_default_nix, "/default.nix")), sep = "\n")
```

The next vignette, `vignette("4b-install_sys_pkgs")`, explains how you can
install tools such as text editors, git, Quarto, TexLive packages, and any other
tool available through `nixpkgs` for your development environments.
The next vignette,
`vignette("4b-installing-system-tools-and-texlive-packages-in-a-nix-environment")`,
explains how you can install tools such as text editors, git, Quarto, TexLive
packages, and any other tool available through `nixpkgs` for your development
environments.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ command line tool (required to edit Quarto documents from R using the `{quarto}`
and git:


```{r parsermd-chunk-1}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "latest",
Expand All @@ -64,7 +64,7 @@ rix(r_ver = "latest",
overwrite = TRUE)
```

```{r parsermd-chunk-2, echo = F}
```{r echo = F}
cat(readLines(paste0(path_default_nix, "/default.nix")), sep = "\n")
```

Expand All @@ -84,7 +84,7 @@ The basic use is to simply add a TexLive package to the `tex_pkgs` argument of `
like this:


```{r parsermd-chunk-3}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "latest",
Expand All @@ -100,7 +100,8 @@ rix(r_ver = "latest",

This will automically add the *small* TexLive distribution available through `nixpkgs`
with the `amsmath` LaTex package. To know more about setting up environments for
literate programming, refer to the vignette `vignette("literate_programming")`.
literate programming, refer to the vignette
`vignette("advanced-topic-building-an-environment-for-literate-programming")`.


## Installing IDEs
Expand Down
15 changes: 8 additions & 7 deletions vignettes/5-interactive-use.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ IDE than RStudio, for example VS Code, Emacs, Vim...

It is also possible to evaluate single functions inside a dedicated, separate,
environment from another, main, interactive R session. For more details
regarding this, refer to the vignette `vignette("subshells")`.
regarding this, refer to the vignette `vignette("advanced-topic-running-r-or-shell-code-in-nix-from-r")`.


## Scenario 1: you installed R and RStudio using the usual installers
Expand All @@ -46,10 +46,11 @@ these project-specific environments. This is because RStudio re-defines many
environment variables and as such, a version of RStudio installed using the
usual installer for your operating system will not be able "to see" an R
interpreter installed with Nix. As stated in the macOS-specific vignette
`vignette("2b-macOS")`, RStudio is not available on macOS through `nixpkgs`. The
following instructions are thus only applicable to Linux and Windows. If you’re
on macOS, read the macOS-specific vignette if that’s not done already, and then
come back here and skip to the "scenario 3" of this vignette.
`vignette("2b-setting-up-and-using-rix-on-macos")`, RStudio is not available on
macOS through `nixpkgs`. The following instructions are thus only applicable to
Linux and Windows. If you’re on macOS, read the macOS-specific vignette if
that’s not done already, and then come back here and skip to the "scenario 3" of
this vignette.

To run a project-specific version of RStudio and R, you will first need to
create a `default.nix` file and build the environment defined therein using Nix.
Expand All @@ -61,7 +62,7 @@ like `C:\Users\Billy\Documents\kmeans`). For example, here is how you could use
`{rix}` to generate the `default.nix` for this environment:


```{r parsermd-chunk-1, include = FALSE}
```{r include = FALSE}
path_default_nix <- tempdir()
rix(r_ver = "latest",
Expand All @@ -74,7 +75,7 @@ rix(r_ver = "latest",
print = TRUE)
```

```{r parsermd-chunk-2, eval = FALSE}
```{r eval = FALSE}
library(rix)
path_to_project <- ~/Documents/kmeans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Because we want to compile a PDF, we also need to have `texlive` installed, as
well as some LaTeX packages. For this, we use the `tex_pkgs` argument:


```{r parsermd-chunk-1}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "4.3.1",
Expand Down Expand Up @@ -109,7 +109,7 @@ So there's an R chunk in `template.qmd` that uses the `{MASS}` package. Change
the environment when built:


```{r parsermd-chunk-2}
```{r}
rix(r_ver = "4.3.1",
r_pkgs = c("quarto", "MASS"),
system_pkgs = "quarto",
Expand Down Expand Up @@ -145,7 +145,7 @@ easier way to list the dependencies and requirements of a LaTeX document.
This is what the final script to build the environment looks like:


```{r parsermd-chunk-3}
```{r}
rix(r_ver = "4.3.1",
r_pkgs = c("quarto", "MASS"),
system_pkgs = "quarto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Fortran. To create a reproducible development environment that makes
the following `rix::rix()` call:


```{r parsermd-chunk-1}
```{r}
path_default_nix <- tempdir()
rix(r_ver = "latest",
Expand Down
Loading

0 comments on commit fc14898

Please sign in to comment.