Skip to content

Commit 0ee2945

Browse files
nbafrankclaude
andcommitted
#70 follow-up: surface .r-version mismatch at R session startup
The CLI's `uvr sync` already refuses to wipe-and-rebuild when the calling R's minor differs from the project pin (since v0.2.19), but a user who *just* opens R against the project — never running sync — wouldn't see that warning and could be running scripts under the wrong R for ages. B-Nilson asked for a session-startup check. Adds a small block to the .uvr-managed `.Rprofile` snippet that: - reads `.r-version` if present - compares its minor to `getRversion()`'s minor - emits a one-line `message()` on mismatch with actionable next steps Existing projects pick up the new check on the next `uvr init` / `uvr sync` via `refresh_uvr_block`, which rewrites the marked block in-place without touching user-added .Rprofile content. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 79c5572 commit 0ee2945

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

crates/uvr/src/commands/init.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,31 @@ const RPROFILE_SNIPPET: &str = r#"# >>> uvr >>>
123123
local({
124124
lib <- file.path(getwd(), ".uvr", "library")
125125
lock <- file.path(getwd(), "uvr.lock")
126+
rver_file <- file.path(getwd(), ".r-version")
126127
count_locked <- function(path) {
127128
if (!file.exists(path)) return(0L)
128129
length(grep("^\\[\\[package\\]\\]", readLines(path, warn = FALSE)))
129130
}
131+
# #70 follow-up: warn when the active R session minor doesn't match
132+
# the project's `.r-version` pin. The CLI's `uvr sync` already refuses
133+
# to wipe-and-rebuild on a minor mismatch since v0.2.19, but a user
134+
# who *just* opens R against the project (no sync yet) wouldn't see
135+
# that warning and could be running scripts under the wrong R for
136+
# ages. Surface it at session startup so the mismatch is visible
137+
# immediately.
138+
if (file.exists(rver_file)) {
139+
pinned <- tryCatch(trimws(readLines(rver_file, warn = FALSE)[1]),
140+
error = function(e) "")
141+
if (nzchar(pinned)) {
142+
active <- as.character(getRversion())
143+
pinned_minor <- paste(strsplit(pinned, "\\.")[[1]][1:2], collapse = ".")
144+
active_minor <- paste(strsplit(active, "\\.")[[1]][1:2], collapse = ".")
145+
if (pinned_minor != active_minor) {
146+
message("uvr: R ", active, " active but .r-version pins ", pinned,
147+
". Restart R against the pinned version, or run uvr::r_pin() to change the pin.")
148+
}
149+
}
150+
}
130151
if (dir.exists(lib)) {
131152
.libPaths(lib)
132153
n_locked <- count_locked(lock)

0 commit comments

Comments
 (0)