Skip to content

Commit

Permalink
keep up with current master
Browse files Browse the repository at this point in the history
Merge branch 'master' into 71-with-nix

# Conflicts:
#	NAMESPACE
  • Loading branch information
philipp-baumann committed Jan 5, 2024
2 parents 2e5a520 + 45397db commit 817ac4a
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 49 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(rix)
export(with_nix)
importFrom(codetools,checkUsage)
importFrom(codetools,findGlobals)
export(tar_nix_ga)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(httr,stop_for_status)
Expand Down
30 changes: 30 additions & 0 deletions R/tar_nix_ga.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# WARNING - Generated by {fusen} from dev/cicd.Rmd: do not edit by hand

#' tar_nix_ga Run a {targets} pipeline on Github Actions.
#' @details This function puts a `.yaml` file inside the `.github/workflows/`
#' folders on the root of your project. This workflow file will use the
#' projects `default.nix` file to generate the development environment on
#' Github Actions and will then run the projects {targets} pipeline. Make
#' sure to give read and write permissions to the Github Actions bot.
#' @return Nothing, copies file to a diretory.
#' @export
tar_nix_ga <- function(){
# Add an empty .gitignore file if there isn’t any

if(file.exists(".gitignore")){
NULL
} else {
file.create(".gitignore")
}

path <- ".github/workflows"

dir.create(path, recursive = TRUE)
source <- system.file(
file.path("extdata", "run-pipeline.yaml"),
package = "rix",
mustWork = TRUE
)
file.copy(source, path, overwrite = TRUE)
invisible()
}
5 changes: 2 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# WARNING - Generated by {fusen} from dev/zzz.Rmd: do not edit by hand

#' zzz
#'
#' Global imports
#' zzz Global imports
#' @noRd
#' @importFrom utils data
utils::globalVariables(c("r_nix_revs"))
56 changes: 36 additions & 20 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ knitr::opts_chunk$set(

<img src="man/figures/logo.png" align="right" style="width: 25%;"/>

# Rix: Reproducible Environments with Nix
# Reproducible Environments with Nix

## Introduction

Expand Down Expand Up @@ -70,7 +70,7 @@ install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev",
library("rix")
```

You can try that everything works well by trying to built the Nix expression
You can check that everything works well by trying to build the Nix expression
that ships with `{rix}`. Nix expressions are typically saved into files with the
name `default.nix`. This expression installs the latest version of R and `{rix}`
in a separate, reproducible environment:
Expand All @@ -88,7 +88,7 @@ nix_build(project_path = ".")

If everything worked well, you should see a file called `result` next to
`default.nix`. You can now enter this newly built development environment by
starting opening a terminal in that folder and typing `nix-shell`. You should
opening a terminal in that folder and typing `nix-shell`. You should
be immediately dropped into an interactive R session.

If you don't have R installed, but have the Nix package manager installed, you
Expand Down Expand Up @@ -135,14 +135,15 @@ The idea of `{rix}` is for you to declare the environment you need, using the
provided `rix()` function, which in turn writes the required expression in a
file for Nix to actually build that environment. You can then use this
environment to either work interactively, or run R scripts. It is possible to
have as many environments as projects. Each environment is isolated (or not,
it's up to you).
have as many environments as projects. Each environment is isolated, but can
still interact with your system's files, unlike with Docker where a volume must
be mounted.

The main function of `{rix}` is called `rix()`. `rix()` has several arguments:

- the R version you need for your project
- a list of R packages that your project needs
- an optional list of additional software (for example, a Python interpreter, or Quarto)
- an optional list of additional software (for example a Python interpreter, or Quarto)
- an optional list with packages to install from Github
- an optional list of LaTeX packages
- whether you want to use RStudio as an IDE for your project (or VS Code, or another environment)
Expand All @@ -159,29 +160,44 @@ rix(r_ver = "latest",
The call above writes a `default.nix` file in the current working directory.
This `default.nix` can in turn be used by Nix to build an environment containing
RStudio, the latest version of R, and the latest versions of the `{dplyr}` and
`{chronicler}` packages. It should be noted that as of September 2023, RStudio
is not available for macOS through Nix so the expression generated by the call
above will not build successfully. It is also not possible to use RStudio
`{chronicler}` packages. It should be noted that as of January 2024, RStudio is
not available for macOS through Nix so the expression generated by the call
above will not build successfully on macOS and is not possible to use RStudio
installed by other means with a Nix environment. This is because RStudio changes
some default environment variables and a globally installed RStudio (the one you
install normally) would not recognize the R installed in the Nix environment.
This is not the case for other IDEs such as VS code or Emacs. Another example:
install normally) would not recognize the R version installed in the Nix
environment. This is not the case for other IDEs such as VS code or Emacs.
Another example:

```{r, eval = FALSE}
rix(r_ver = "4.2.2", r_pkgs = c("dplyr", "chronicler"), ide = "code")
rix(r_ver = "4.2.2",
r_pkgs = c("dplyr", "chronicler"),
ide = "code")
```

This call will generate a `default.nix` that installs R version 4.2.2, with the
`{dplyr}` and `{chronicler}` packages. Because the user wishes to use VS Code,
the `ide` argument was set to "code". This installs the required
`{languageserver}` package as well, but unlike `ide = "rstudio"` does not
install VS Code in that environment. Users should instead use the globally
installed VS Code by starting it from that environment.
installed VS Code by starting it from that environment. If you wish to also
install VS Code using Nix, you could change the above expression to this:

```{r, eval = FALSE}
rix(r_ver = "4.2.2",
r_pkgs = c("dplyr", "chronicler"),
system_pkgs = "vscodium",
ide = "code")
```

or change "vscodium" to "vscode" if you prefer the MS branded version.

It's also possible to install specific versions of packages:

```{r, eval = FALSE}
rix(r_ver = "latest", r_pkgs = c("dplyr@1.0.0"), ide = "code")
rix(r_ver = "latest",
r_pkgs = c("dplyr@1.0.0"),
ide = "code")
```

but usually it is better to build an environment using the version of R that was
Expand Down Expand Up @@ -293,13 +309,13 @@ rix(r_ver = "latest",
r_pkgs = c("dplyr", "ggplot2"),
system_pkgs = NULL,
git_pkgs = NULL,
ide = "rstudio",
ide = "other",
project_path = ".",
overwrite = TRUE)
```

to generate a `default.nix`, and then use that file to generate an environment
with R, Rstudio, `{dplyr}` and `{ggplot2}`. If you need to add packages for your
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`.

## Installing Nix
Expand Down Expand Up @@ -333,11 +349,11 @@ wsl --shutdown
# relaunch Ubuntu WSL2
```

Afterwards, you can install Nix like business as usual. You can proceed with
the Determinant Systems installer. If you cannot or have decided not to activate
Afterwards, you can install Nix like business as usual. You can proceed with the
Determinate Systems installer. If you cannot or have decided not to activate
systemd, then you have to append `--init none` to the command. More details
about this you can find at
[The Determinante Nix Installer](https://github.com/DeterminateSystems/nix-installer).
about this you can find at [The Determinante Nix
Installer](https://github.com/DeterminateSystems/nix-installer).

### Installing Nix using the Determinate Systems installer

Expand Down
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- [Rix: Reproducible Environments with
Nix](#rix-reproducible-environments-with-nix)
- [Reproducible Environments with
Nix](#reproducible-environments-with-nix)
- [Introduction](#introduction)
- [Returning users](#returning-users)
- [The Nix package manager](#the-nix-package-manager)
Expand Down Expand Up @@ -29,7 +29,7 @@ rix](https://b-rodrigues.r-universe.dev/badges/rix?scale=1&color=pink&style=roun

<img src="man/figures/logo.png" align="right" style="width: 25%;"/>

# Rix: Reproducible Environments with Nix
# Reproducible Environments with Nix

## Introduction

Expand Down Expand Up @@ -78,7 +78,7 @@ install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev",
library("rix")
```

You can try that everything works well by trying to built the Nix
You can check that everything works well by trying to build the Nix
expression that ships with `{rix}`. Nix expressions are typically saved
into files with the name `default.nix`. This expression installs the
latest version of R and `{rix}` in a separate, reproducible environment:
Expand All @@ -96,9 +96,8 @@ nix_build(project_path = ".")

If everything worked well, you should see a file called `result` next to
`default.nix`. You can now enter this newly built development
environment by starting opening a terminal in that folder and typing
`nix-shell`. You should be immediately dropped into an interactive R
session.
environment by opening a terminal in that folder and typing `nix-shell`.
You should be immediately dropped into an interactive R session.

If you don’t have R installed, but have the Nix package manager
installed, you can run a temporary R session with R using this command
Expand Down Expand Up @@ -146,14 +145,15 @@ using the provided `rix()` function, which in turn writes the required
expression in a file for Nix to actually build that environment. You can
then use this environment to either work interactively, or run R
scripts. It is possible to have as many environments as projects. Each
environment is isolated (or not, it’s up to you).
environment is isolated, but can still interact with your system’s
files, unlike with Docker where a volume must be mounted.

The main function of `{rix}` is called `rix()`. `rix()` has several
arguments:

- the R version you need for your project
- a list of R packages that your project needs
- an optional list of additional software (for example, a Python
- an optional list of additional software (for example a Python
interpreter, or Quarto)
- an optional list with packages to install from Github
- an optional list of LaTeX packages
Expand All @@ -173,17 +173,19 @@ The call above writes a `default.nix` file in the current working
directory. This `default.nix` can in turn be used by Nix to build an
environment containing RStudio, the latest version of R, and the latest
versions of the `{dplyr}` and `{chronicler}` packages. It should be
noted that as of September 2023, RStudio is not available for macOS
noted that as of January 2024, RStudio is not available for macOS
through Nix so the expression generated by the call above will not build
successfully. It is also not possible to use RStudio installed by other
means with a Nix environment. This is because RStudio changes some
successfully on macOS and is not possible to use RStudio installed by
other means with a Nix environment. This is because RStudio changes some
default environment variables and a globally installed RStudio (the one
you install normally) would not recognize the R installed in the Nix
environment. This is not the case for other IDEs such as VS code or
you install normally) would not recognize the R version installed in the
Nix environment. This is not the case for other IDEs such as VS code or
Emacs. Another example:

``` r
rix(r_ver = "4.2.2", r_pkgs = c("dplyr", "chronicler"), ide = "code")
rix(r_ver = "4.2.2",
r_pkgs = c("dplyr", "chronicler"),
ide = "code")
```

This call will generate a `default.nix` that installs R version 4.2.2,
Expand All @@ -192,12 +194,24 @@ to use VS Code, the `ide` argument was set to “code”. This installs the
required `{languageserver}` package as well, but unlike
`ide = "rstudio"` does not install VS Code in that environment. Users
should instead use the globally installed VS Code by starting it from
that environment.
that environment. If you wish to also install VS Code using Nix, you
could change the above expression to this:

``` r
rix(r_ver = "4.2.2",
r_pkgs = c("dplyr", "chronicler"),
system_pkgs = "vscodium",
ide = "code")
```

or change “vscodium” to “vscode” if you prefer the MS branded version.

It’s also possible to install specific versions of packages:

``` r
rix(r_ver = "latest", r_pkgs = c("dplyr@1.0.0"), ide = "code")
rix(r_ver = "latest",
r_pkgs = c("dplyr@1.0.0"),
ide = "code")
```

but usually it is better to build an environment using the version of R
Expand Down Expand Up @@ -302,14 +316,14 @@ now run something like this:
r_pkgs = c("dplyr", "ggplot2"),
system_pkgs = NULL,
git_pkgs = NULL,
ide = "rstudio",
ide = "other",
project_path = ".",
overwrite = TRUE)

to generate a `default.nix`, and then use that file to generate an
environment with R, Rstudio, `{dplyr}` and `{ggplot2}`. If you need to
add packages for your project, rerun the command above, but add the
needed packages to `r_pkgs`.
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`.

## Installing Nix

Expand Down Expand Up @@ -342,7 +356,7 @@ wsl --shutdown
```

Afterwards, you can install Nix like business as usual. You can proceed
with the Determinant Systems installer. If you cannot or have decided
with the Determinate Systems installer. If you cannot or have decided
not to activate systemd, then you have to append `--init none` to the
command. More details about this you can find at [The Determinante Nix
Installer](https://github.com/DeterminateSystems/nix-installer).
Expand Down
6 changes: 6 additions & 0 deletions dev/0-dev_history.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ fusen::inflate(flat_file = "dev/build_envs.Rmd",
overwrite = TRUE)
```

```{r}
fusen::inflate(flat_file = "dev/cicd.Rmd",
vignette_name = NA,
overwrite = TRUE)
```


```{r}
fusen::inflate(flat_file = "dev/zzz.Rmd",
Expand Down
55 changes: 55 additions & 0 deletions dev/cicd.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: "Functions for Github Actions CI/CD service"
output: html_document
editor_options:
chunk_output_type: console
---

```{r development, include=FALSE}
library(testthat)
```

<!--
You need to run the 'description' chunk in the '0-dev_history.Rmd' file before continuing your code there.
-->

```{r development-load}
# Load already included functions if relevant
pkgload::load_all(export_all = FALSE)
```

The function below copies a Github actions workflow file into the
`.github/workflows/run-pipeline.yaml`:

```{r function-tar_nix_ga}
#' tar_nix_ga Run a {targets} pipeline on Github Actions.
#' @details This function puts a `.yaml` file inside the `.github/workflows/`
#' folders on the root of your project. This workflow file will use the
#' projects `default.nix` file to generate the development environment on
#' Github Actions and will then run the projects {targets} pipeline. Make
#' sure to give read and write permissions to the Github Actions bot.
#' @return Nothing, copies file to a diretory.
#' @export
tar_nix_ga <- function(){
# Add an empty .gitignore file if there isn’t any
if(file.exists(".gitignore")){
NULL
} else {
file.create(".gitignore")
}
path <- ".github/workflows"
dir.create(path, recursive = TRUE)
source <- system.file(
file.path("extdata", "run-pipeline.yaml"),
package = "rix",
mustWork = TRUE
)
file.copy(source, path, overwrite = TRUE)
invisible()
}
```

Be sure to give Github Actions workflows read and write permissions.
Loading

0 comments on commit 817ac4a

Please sign in to comment.