Record the R and package versions a result depends on¶
Draft: not yet validated
The code on this page was run in MESA RStudio Geospatial on 2026-11-17 (R 4.6.2), by the AI assistant that drafted it, and gave the results quoted in the steps. No person has yet followed the steps. Tell us what you find.
The software in a MESA app changes when the app is rebuilt. A number you computed today may not come out the same next year, and without a record you cannot tell whether the data or the software changed.
You will: have three small files beside your work that say which R and which package versions it ran on.
Time: 5 minutes. You need: the mesa-practice folder from
Load a file from your Data Store in RStudio, or a folder of your
own, in MESA RStudio Geospatial with R's working folder set to it.
Steps¶
-
In the Console, check the R version:
R.version.stringYou should see: one line, such as
[1] "R version 4.6.2 (2026-10-29)". -
Write every installed package and its version to a file:
pkgs <- as.data.frame(installed.packages()[, c("Package", "Version")], row.names = FALSE) write.csv(pkgs, "r-packages.csv", row.names = FALSE)You should see: no output, and
pkgsin the Environment tab at the top right. -
Count what was recorded:
nrow(pkgs)You should see: a few hundred, one row for each package. In our test,
[1] 288. -
Look up the packages your work loads. For the practice tutorials:
pkgs[pkgs$Package %in% c("sf", "duckdb", "terra"), ]You should see: one row for each, with its version. In our test,
duckdb2.0.0,sf1.1-3 andterra1.9-50. The number at the start of each row is its place in the list. -
Record the session: the operating system, and the packages loaded right now.
writeLines(capture.output(sessionInfo()), "r-session.txt")You should see: no output. Run this at the end of your work, when everything the work uses has been loaded.
-
Write a one-line note that ties the files together and dates them:
writeLines(paste0(R.version.string, ", packages in r-packages.csv, recorded ", Sys.Date()), "r-environment.txt") readLines("r-environment.txt")You should see: the note. In our test,
[1] "R version 4.6.2 (2026-10-29), packages in r-packages.csv, recorded 2026-11-17".
Check it worked¶
list.files(pattern = "^r-") names r-environment.txt, r-packages.csv and
r-session.txt, and step 4 shows a version for each package your work loads.
If it didn't¶
Step 4 prints [1] Package Version and <0 rows>. None of the names matched
what is installed. Names are case-sensitive: search with
pkgs[grepl("duck", pkgs$Package, ignore.case = TRUE), ] and use the spelling it
shows.
Next¶
- These files record the software; they do not rebuild it. To run old work again you need an app with the same versions, or to install them yourself.
- Record again whenever a result goes into a report: the date in
r-environment.txtsays which run the record belongs to. - Leave an R script someone else can rerun
- Write a README for a data folder, from RStudio, and mention these three files in it.
- The same task in Python: Record the software versions a result depends on.
Not yet validated by a person in MESA RStudio Geospatial. Drafted with AI assistance on 2026-11-17; the code was run there that day (R 4.6.2).
Machine-readable versions of this page: Markdown twin · raw source on GitHub · llms.txt · llms-full.txt (whole site). See For AI agents.