R Environments
kapsl runs R via Alpine's R package
— there's no per-minor-version selection the way Python/Node have (Alpine
ships one current R release), so kapsl R always runs against that version.
The tool name is capital R, matching the real command on Linux (there's
no lowercase r binary; Rscript is a separate, non-interactive command
that kapsl uses under the hood).
Inline packages
Append :pkg1,pkg2 to install R packages before running:
kapsl R:dplyr,ggplot2 script.Rrenv.lock
kapsl -e @renv:renv.lock R script.R
kapsl reads renv.lock, restores the packages into the image, caches it, and runs the script.
Auto-detect
kapsl -e @renv R script.R # finds renv.lock in CWDShebang scripts
#!/usr/bin/env -S kapsl R:dplyr
library(dplyr)
mtcars |>
group_by(cyl) |>
summarise(mean_mpg = mean(mpg)) |>
print()chmod +x script.R
./script.RNative packages
Many CRAN packages compile native C code — R has no wheel-equivalent
prebuilt-binary system. kapsl handles this the same way it does for Python's
wheel-less packages: package installs build against a compiler-having
variant of the R image, kept separate from the small image a bare kapsl R
pulls.