Skip to content
Closed
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
57 changes: 6 additions & 51 deletions .github/workflows/deploy-book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,22 @@ jobs:
- name: Install dependencies
run: make init REQUIREMENTS_FILE=requirements-execution.lock.txt

- name: Register Python and Bash kernels
run: |
. .venv/bin/activate
python -m ipykernel install --sys-prefix --name python3 --display-name "Python 3"
python -m bash_kernel.install

- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.3.3'
use-public-rspm: true

- name: Install R packages and register kernel
env:
CRAN_REPO: https://packagemanager.posit.co/cran/__linux__/noble/2026-10-01
run: |
. .venv/bin/activate
Rscript -e 'options(repos = c(CRAN = Sys.getenv("CRAN_REPO"))); install.packages(readLines("requirements-r.txt"))'
ir_kernel_spec=$(Rscript -e 'cat(system.file("kernelspec", package = "IRkernel"))')
jupyter kernelspec install --user --replace --name ir "$ir_kernel_spec"

- name: Verify notebook kernels
run: |
. .venv/bin/activate
python - <<'PY'
import json
import subprocess

kernels = json.loads(subprocess.check_output(["jupyter", "kernelspec", "list", "--json"]))["kernelspecs"]
missing = {"python3", "ir", "bash"} - kernels.keys()
if missing:
raise SystemExit(f"Missing notebook kernels: {', '.join(sorted(missing))}")
PY

- name: Configure strict notebook execution
run: |
. .venv/bin/activate
python - <<'PY'
from pathlib import Path

import yaml

config_path = Path("content/_config.yml")
config = yaml.safe_load(config_path.read_text(encoding="utf-8"))
execution = config.setdefault("execute", {})
execution["execute_notebooks"] = "force"
execution["allow_errors"] = False
execution["timeout"] = 180
config.setdefault("sphinx", {}).setdefault("config", {})[
"nb_execution_raise_on_error"
] = True
Path("content/_config_ci.yml").write_text(
yaml.safe_dump(config, sort_keys=False), encoding="utf-8"
)
PY
- name: Check shared R observations contract
run: Rscript scripts/check_r_observations.R

- name: Check, execute, and build book
# Strict forced notebook execution is temporarily suspended. Restore it
# through https://github.com/MulQuaBio/MQB/issues/205.
- name: Check and build book
env:
MQB_NOTEBOOK_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
MQB_NOTEBOOK_REF: ${{ github.event.pull_request.head.sha || github.sha }}
run: PYTHONPATH="$GITHUB_WORKSPACE" make test BOOK_CONFIG=content/_config_ci.yml BOOK_BUILD_ARGS=--all
run: PYTHONPATH="$GITHUB_WORKSPACE" make test

- name: Upload built book
uses: actions/upload-artifact@v7
Expand Down
1 change: 1 addition & 0 deletions content/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ parts:
- file: appendices/terms
- file: appendices/macos-tools
- file: appendices/python-environments
- file: appendices/r-setup
- file: appendices/vscode
- file: appendices/git-ssh
- file: notebooks/appendix-jupy-intro
Expand Down
94 changes: 94 additions & 0 deletions content/appendices/r-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
(r-setup)=
# R Installation and User Libraries

R is the program that runs R code. `R` opens an interactive console; `Rscript` runs a saved script from a terminal. RStudio and Visual Studio Code are optional editors: neither installs nor replaces R itself.

If you are using a managed course computer, use its installed R first. Do not reinstall or upgrade managed software during a class unless teaching staff ask you to.

## Check before installing

Open a terminal (PowerShell or Command Prompt on Windows) and run:

```bash
R --version
Rscript --version
```

If both commands report a version, continue to {ref}`r-setup-check`. If an editor cannot find R but these commands work, fix the editor configuration rather than installing a second copy.

## Install R

Use the official [Comprehensive R Archive Network (CRAN)](https://cran.r-project.org/) downloads.

- **Windows:** use [R for Windows](https://cran.r-project.org/bin/windows/base/) and accept the standard per-machine or managed-machine choices available to you. Open a new terminal after installation.
- **macOS:** use [R for macOS](https://cran.r-project.org/bin/macosx/) and choose the installer that matches your Mac and supported macOS version. Open a new terminal afterwards.
- **Ubuntu:** follow the [CRAN Ubuntu instructions](https://cran.r-project.org/bin/linux/ubuntu/) when you need CRAN's current release. On a managed machine, ask the administrator. For a simple distribution-provided installation on a machine you administer, `sudo apt update` followed by `sudo apt install r-base` is sufficient, but the Ubuntu release may provide an older R version. See {ref}`ubuntu-admin` before changing repositories or system packages.

Install R before an editor. If you want RStudio Desktop, use the current [Posit download page](https://posit.co/download/rstudio-desktop/) and check its [supported platforms](https://docs.posit.co/platform-support.html). For VS Code, follow {ref}`vscode-setup` after the terminal checks above work.

## Install packages without running R as administrator

R searches one or more package libraries. Inspect them in the R console:

```r
.libPaths()
Sys.getenv("R_LIBS_USER")
```

Install course packages from an ordinary R session:

```r
install.packages("package_name", repos = "https://cloud.r-project.org")
```

If R asks to create a personal library, answer **yes**. This is the normal, recommended location for packages that belong to your account. If needed, create R's default user-library directory and restart R:

```r
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE, showWarnings = FALSE)
```

Do **not** start R with `sudo`, and do not make a system library writable to everyone. Administrator access may be needed to install R itself or a missing operating-system development library, but it is not the normal way to install an R package. Read the package's actual error first; Windows users only need [Rtools](https://cran.r-project.org/bin/windows/Rtools/) when a package must be compiled from source.

(r-setup-check)=
## Run a clean project check

Create a disposable folder with `code`, `data`, and `results` subfolders. Save this as `code/r_setup_check.R`:

```r
cat(R.version.string, "\n")
cat("Working directory:", getwd(), "\n")
cat("First library:", .libPaths()[1], "\n")

dir.create("results", showWarnings = FALSE)
png("results/r_setup_check.png", width = 640, height = 480)
plot(cars, main = "R setup check")
dev.off()

stopifnot(file.exists("results/r_setup_check.png"))
cat("R setup check passed\n")
```

In a terminal, change to the **project root**, then run:

```bash
Rscript code/r_setup_check.R
```

The command should print `R setup check passed` and create `results/r_setup_check.png`. Starting every scripted analysis at the project root keeps paths such as `data/input.csv` and `results/figure.png` portable. Do not put a computer-specific `setwd()` in a shared script.

## Troubleshooting evidence

When asking for help, copy the exact error and report your operating system plus the output of:

```r
R.version.string
R.home()
.libPaths()
Sys.which(c("R", "Rscript"))
```

Also say whether the failure occurs in a terminal, RStudio, VS Code, or a notebook. An R notebook additionally needs the separate {ref}`jupyter-r-kernel`; a Python environment does not install or isolate R packages.

## Sources and verification

MQB guidance revised 10 October 2026 against the official [R installation and administration manual](https://cran.r-project.org/doc/manuals/r-release/R-admin.html), CRAN platform downloads, the [RStudio IDE user guide](https://docs.posit.co/ide/user/), and Posit's platform-support policy. The command-line workflow uses base R and is editor-independent. Platform installers and graphical editor discovery were not runtime-tested on this maintainer machine; use the linked current platform instructions if their screens differ.
1 change: 1 addition & 0 deletions content/appendices/tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ If a setup page uses a word you do not know, look it up in [Key computing terms]
- Choosing a Linux environment or configuring Ubuntu: [Linux Setup and Ubuntu Administration](ubuntu-admin.md)
- Setting up macOS command-line tools: [macOS Tools and Homebrew](macos-tools.md)
- Installing Python and managing project packages: [Python Installation and Environments](python-environments.md)
- Installing R and using a personal package library: [R Installation and User Libraries](r-setup.md)
- Working with Python, R and notebooks in an editor: [VS Code for MQB](vscode.md)
- Setting up GitHub access and project remotes: [Git, GitHub and SSH Setup](git-ssh.md)
- If you’re new to notebooks/Jupyter: [Jupyter / notebooks intro](../notebooks/appendix-jupy-intro)
Expand Down
4 changes: 2 additions & 2 deletions content/appendices/vscode.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(vscode-setup)=
# VS Code for MQB

Visual Studio Code (VS Code) is a multilingual editor that can work with Python scripts, R scripts, terminals and Jupyter notebooks in one project folder. It is an option, not a requirement: use RStudio where that better suits your R work. This page assumes that you already have the Python environment from {ref}`python-environments` and, for the R route, a working R installation. A separate R setup guide will cover installing R itself.
Visual Studio Code (VS Code) is a multilingual editor that can work with Python scripts, R scripts, terminals and Jupyter notebooks in one project folder. It is an option, not a requirement: use RStudio where that better suits your R work. This page assumes that you already have the Python environment from {ref}`python-environments` and, for the R route, a working installation from {ref}`r-setup`.

## Before you start

Expand Down Expand Up @@ -131,7 +131,7 @@ If **R: Create R Terminal** cannot find R, first run `R --version` in the VS Cod
}
```

Use your installed version and path; do not paste the example unchanged. On macOS or Linux, resolve the path visible to VS Code's terminal before adding any extension setting. A dedicated R setup page will cover installation and user-library troubleshooting.
Use your installed version and path; do not paste the example unchanged. On macOS or Linux, resolve the path visible to VS Code's terminal before adding any extension setting. See {ref}`r-setup` for installation and user-library troubleshooting.

R debugging is separate from the R language extension and needs its own supported debugger and prerequisites. Do not claim a script has been debugged merely because it ran. An R `.ipynb` notebook uses an IRkernel chosen in the notebook kernel picker; it is distinct from sending code to an `.R` terminal.

Expand Down
2 changes: 1 addition & 1 deletion content/notebooks/appendix-data-python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
"MyDF = pd.DataFrame({\n",
" 'col1': ['Var1', 'Var2', 'Var3', 'Var4'],\n",
" 'col2': ['Grass', 'rabbit', 'Fox', 'Wolf'],\n",
" 'col3': [1, 2, sc.nan, 4]\n",
" 'col3': [1, 2, float(\"nan\"), 4]\n",
"})\n",
"\n",
"MyDF"
Expand Down
4 changes: 2 additions & 2 deletions content/notebooks/appendix-jupy-intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"\n",
"* **Jupyter Notebook 7 and newer** provides a focused browser-based notebook interface. It is not the old classic Notebook 6 interface.\n",
"* **JupyterLab** provides a tabbed workspace for notebooks, text editors and terminals. It uses the same notebook format and kernel system.\n",
"* **VS Code** can open notebooks through its Jupyter extension. Its notebook kernel must be selected independently of any terminal environment. Dedicated VS Code guidance will be added with the editor-setup phase.\n",
"* **VS Code** can open notebooks through its Jupyter extension. Its notebook kernel must be selected independently of any terminal environment. See [VS Code for MQB](../appendices/vscode.md).\n",
"\n",
"The cell-based lessons below apply to both browser interfaces. Some historical screenshots show classic Notebook menus; use the equivalent command in your installed interface rather than downgrading to match an image. There is no need to install both browser interfaces to use obsolete extensions."
]
Expand Down Expand Up @@ -128,7 +128,7 @@
"(jupyter-r-kernel)=\n",
"#### The R kernel\n",
"\n",
"R needs a separate R installation and the `IRkernel` R package; installing `ipykernel` does not provide R. Start `R` from a terminal where the intended Jupyter installation is available. In the **R console**, inspect `R.home()`, `.libPaths()` and `Sys.which(\"jupyter\")`. If Jupyter is missing, fix that terminal's environment before registration.\n",
"R needs a separate R installation and the `IRkernel` R package; installing `ipykernel` does not provide R. Complete [R Installation and User Libraries](../appendices/r-setup.md) first, then start `R` from a terminal where the intended Jupyter installation is available. In the **R console**, inspect `R.home()`, `.libPaths()` and `Sys.which(\"jupyter\")`. If Jupyter is missing, fix that terminal's environment before registration.\n",
"\n",
"For a machine with the required R/compiler/system-library prerequisites, install the released CRAN package into your writable R library and register it for your account:\n",
"\n",
Expand Down
Loading