Staff scientists / RSE @LCBC_UiO & @LifebrainEU. She/Her.
PhD Cognitive Neurosciences 🧠
@rladies.org Global Team.
#Rstats #Nerd 🌈🏳️🌈

@drmowinckels.io
Staff scientists / RSE @LCBC_UiO & @LifebrainEU. She/Her.
PhD Cognitive Neurosciences 🧠
@rladies.org Global Team.
#Rstats #Nerd 🌈🏳️🌈
Need everything a setup script exports? Run it in bash with env at the end and parse the output in R. The repo has a ten-line env_from_script() for it.
"current" keeps the existing environment and adds or overrides what you list. With system2(), withr::with_envvar() does the same job.
R can't source a shell script. And Sys.setenv() leaks into the rest of the user's session. Better: set them for just the one call. processx::run(cmd, args, env = c("current", SUBJECTS_DIR = dir))
#RCLIAdvent2026 Day 5: environment variables #rstats
Many CLIs read config from env vars. FreeSurfer needs FREESURFER_HOME and SUBJECTS_DIR, which users normally set by sourcing FreeSurfer's setup script in their shell.
Always an honor to be mentioned in R Weekly!
Episode 250 (!) of R Weekly Highlights is out! serve.podhome.fm/episodepage/... 🤔 The NOT_CRAN line @drmowinckels.io 📦 covr 4.0.0 @jimhester.bsky.social 🤖 Introducing mordew @colinfay.bsky.social h/t @mike-thomas.bsky.social & Sam Parmar 🙏 #rstats #databs
Episode 250 (!) of R Weekly Highlights is out! serve.podhome.fm/episodepage/...
🤔 The NOT_CRAN line @drmowinckels.io
📦 covr 4.0.0 @jimhester.bsky.social
🤖 Introducing mordew @colinfay.bsky.social
h/t @mike-thomas.bsky.social & Sam Parmar 🙏
I don't know how many times I've watched this on repeat. Her control is just so amazing.
Nothing found? Fail with a cli error that says exactly which option to set. The option comes first so users can always override what the package guesses.
So my find_tool() checks four places, in order: 1. an R option, e.g. options(freesurfer.recon_all = "/path/to/recon-all") 2. an environment variable 3. Sys.which() 4. known install locations, like $FREESURFER_HOME/bin
Sys.which("pandoc") searches your PATH. But GUI apps on macOS often don't inherit the PATH your shell sets up. The tool is installed and R still can't see it.
#RCLIAdvent2026 Day 4: finding the executable #rstats
The most common bug report for a wrapper package: "it works in the terminal but not in RStudio."
Oh yes! We have all been down this rabbit hole at home point or other. Floating point numbers are no joke!
I can't believe I didn't know of it before I was researching this calendar! I'm very much looking forward to exploring refactoring some packages.
Two more worth knowing:
- timeout = to stop a job that hangs
- echo = TRUE to stream output live
For a FreeSurfer job that runs for hours, those matter a lot.
What you get: - arguments as a character vector, no shell, nothing to quote - a real R error on a non-zero exit (or error_on_status = FALSE to handle it yourself) - res$stdout and res$stderr as plain strings, ready to parse
#RCLIAdvent2026 Day 3: processx::run() #rstats
Yesterday's system() and system2() fail silently. processx::run() doesn't.
Honest admission: I don't use it in my own wrappers yet. Researching this calendar sold me on it.
res <- processx::run("pandoc", "--version")
Tomorrow: the package I should have been reaching for instead.
The trap: when the command fails, R doesn't throw an error. You get a warning, and the exit code is tucked away in attr(out, "status"). If your wrapper doesn't check it, a failed run looks just like a successful one.
Both print to the console by default and return the exit code, not the text. intern = TRUE in system(), and stdout = TRUE in system2(), are what say "hand me the output as a character vector instead". Forget them and you get a number where you wanted lines.
system() takes a single string and hands it to the shell: system("git --version", intern = TRUE) system2() takes the command and its arguments separately, which is easier to build from R values: system2("git", "--version", stdout = TRUE)