Terminal: Ghostty. Theme: Dracula+. Font family: Iosevka Term.
Update (2025-02-13): The issue still exists in RStudio 2024.12.1. The fix still applies.
Update (2025-03-05): The issue has been fixed in RStudio >= 2025.04.0+323.
TL;DR: The fix
The following script detects newly added ProjectID lines in .Rproj files
using git diff. If detected, it removes the line and saves the modified
.Rproj file.
# Remove ProjectID from .Rproj files if freshly added
local({
xfun <- requireNamespace("xfun", quietly = TRUE)
rproj_files <- list.files(pattern = "\\.Rproj$", full.names = TRUE)
if (!xfun || length(rproj_files) == 0L) return(invisible(NULL))
lapply(rproj_files, function(f) {
diff_cmd <- system(paste("git diff --", shQuote(f)), intern = TRUE)
diff_out <- tryCatch(diff_cmd, error = function(e) character(0))
if (any(grepl("^\\+ProjectId: ", diff_out))) {
dcf_old <- xfun::read_utf8(f)
dcf_new <- dcf_old[!grepl("^ProjectId: ", dcf_old)]
xfun::write_utf8(dcf_new, f)
}
})
invisible(NULL)
})
To apply this fix, add the script to your project-specific .Rprofile or the
user-specific ~/.Rprofile. It will execute on every
R startup.
The script has been tested with RStudio IDE 2024.12.0 on Windows, macOS, and Linux.
Requirements of the script:
- The project must use Git for version control.
gitmust be accessible from the command-line (Windows how-to).- The xfun package is installed for handling UTF-8 encoded files.
The issue
In RStudio 2024.12.0, opening an R package or project automatically adds a
ProjectID field to the .Rproj file, as shown in the screenshot above.
This feature was introduced in
rstudio/rstudio#15140.
It was designed to accurately map projects with their .Rproj.user/
directories, which can now be stored externally—outside of the project.
While this feature serves a clear purpose, the current implementation
introduces some unintended side effects. For example, it may create
unnecessary diffs
in version control, with no clear lifecycle for the ProjectID.
Team members collolaborating with different RStudio versions might also
get conflicting edits,
leading to additional version control noise.
Long-term and short-term solutions
This behavior has been improved in
rstudio/rstudio#15654,
where ProjectID is only added when external storage for .Rproj.user/
is required. However, until a fixed version is released, or if users are
stuck with RStudio 2024.12.0, a temporary user-space solution could be useful.
Why this fix works
The modification to .Rproj files occurs in RStudio IDE logic before the
R process starts, meaning we cannot prevent the addition of ProjectID.
However, we can reliably detect the change via git diff and revert it
when R starts. The script provided at the beginning of this post
automates this process.