Outside VS Code
Settings Sync only carries what is inside VS Code (what it does not carry). The rest lives in a few small files. I keep them in the OneDrive Documents folder, so OneDrive shares them between my machines. Because they are shared, they follow the same rule as the VS Code settings. So they contain no user names, and anything only one machine has (a D: drive, TinyTeX) is checked before use.
.Rprofile
R runs a user .Rprofile at start-up. It reads:
- a
.Rprofilein the current folder, if there is one; - otherwise, the one in
R_USER, which on Windows is theDocumentsfolder (with OneDrive folder backup, that isOneDrive\Documents).
In renv projects, the project’s own .Rprofile activates renv, and renv does not load the user .Rprofile unless you set renv.config.user.profile = TRUE. So none of the below applies inside renv projects (which includes projects from my project template).
A stray .Rprofile in a project or home folder silently replaces the user one; keep one. Check which one wins with Sys.getenv("R_USER") and file.exists(".Rprofile").
What it does, block by block
| Block | What it does | Why |
|---|---|---|
| httpgd in VS Code | Only when interactive and inside VS Code (TERM_PROGRAM == "vscode") and if httpgd is installed: sets vsc.rstudioapi, vsc.use_httpgd, vsc.plot = FALSE, and makes httpgd the default graphics device. |
Plots go to the httpgd viewer in VS Code. vsc.rstudioapi lets packages that call rstudioapi (add-ins, usethis) work in VS Code. |
| btw | Starts btw::btw_mcp_session() when interactive, only if btw is installed for this R version. |
Lets coding assistants (through MCP) see the live R session: objects, help, installed packages. |
| radian options | radian.auto_match = FALSE, radian.auto_indentation = FALSE. |
radian would otherwise insert closing brackets and indent as you type. |
| RStudio’s pandoc | Sets RSTUDIO_PANDOC to RStudio’s bundled pandoc folder, if it exists. |
rmarkdown outside RStudio then finds pandoc without a separate install. |
| Temporary folder | Sets TEMP/TMP to D:/Temp, only if that folder exists. |
Big temporary files go to a second drive on the machine that has one. On other machines nothing changes. |
| TinyTeX | Appends TinyTeX’s bin\windows to PATH, if installed and not there yet. |
PDF output from R Markdown / Quarto started from R. |
The quarto R package and rmarkdown find Quarto on PATH, which is the all-users install.
Show the full file: .Rprofile
# User .Rprofile. R reads it from R_USER (= OneDrive\Documents), so OneDrive
# shares it between machines: keep it machine-neutral (no user names, no
# paths that exist on only one machine; guard anything optional).
# VS Code: plots go to httpgd (vscode-R shows them in its viewer).
if (interactive() && Sys.getenv("TERM_PROGRAM") == "vscode") {
if ("httpgd" %in% .packages(all.available = TRUE)) {
options(vsc.rstudioapi = TRUE)
options(vsc.use_httpgd = TRUE)
options(vsc.plot = FALSE)
options(device = function(...) {
httpgd::hgd(silent = FALSE)
})
}
}
# Expose the session to coding assistants (MCP), when btw is installed for
# this R version (each R version has its own library).
if (interactive() && requireNamespace("btw", quietly = TRUE)) {
btw::btw_mcp_session()
}
# radian: no automatic bracket matching or indentation.
options(radian.auto_match = FALSE)
options(radian.auto_indentation = FALSE)
local({
# Pandoc bundled with RStudio, for rmarkdown outside RStudio.
rstudio_pandoc <- "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"
if (dir.exists(rstudio_pandoc)) {
Sys.setenv(RSTUDIO_PANDOC = rstudio_pandoc)
}
# Large temporary files on a second drive, where the machine has one.
temp_dir <- "D:/Temp"
if (dir.exists(temp_dir)) {
Sys.setenv(TEMP = temp_dir, TMP = temp_dir)
}
# TinyTeX (LaTeX for PDF output), if installed and not already on PATH.
tinytex_bin <- file.path(Sys.getenv("APPDATA"), "TinyTeX", "bin", "windows")
path_entries <- normalizePath(
strsplit(Sys.getenv("PATH"), ";", fixed = TRUE)[[1]],
winslash = "/",
mustWork = FALSE
)
if (
dir.exists(tinytex_bin) &&
!normalizePath(tinytex_bin, winslash = "/") %in% path_entries
) {
Sys.setenv(PATH = paste(Sys.getenv("PATH"), tinytex_bin, sep = ";"))
}
})(Published as Rprofile.R so that browsers show it; save it as .Rprofile in your Documents folder.)
radian
radian has its own profile file (~/.radian_profile), but I do not use one: the two options I change are R options, so they are in .Rprofile above.
radian uses the R on PATH unless R_HOME is set (R versions), so I do not set R_HOME (PATH rules).
PowerShell
PowerShell 7 reads two profile files from Documents\PowerShell\. Both are shared through OneDrive.
profile.ps1 (all PowerShell hosts) is created by rig system fix-r-alias. It removes the built-in r alias (Invoke-History), so that typing R starts R:
Show the full file: powershell/profile.ps1
# >>> rig: enable the 'R' command >>>
# Remove the built-in 'r' -> Invoke-History alias so that 'R' starts R.
if (Test-Path Alias:\r) { Remove-Item Alias:\r -Force }
# <<< rig: enable the 'R' command <<<Microsoft.PowerShell_profile.ps1 (the console and VS Code terminals) loads Oh My Posh, a prompt theme that shows the git branch and status. It needs winget install JanDeDobbeleer.OhMyPosh and, for the icons, a Nerd Font set as the terminal font.
Show the full file: powershell/Microsoft.PowerShell_profile.ps1
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-ExpressionDownload Microsoft.PowerShell_profile.ps1
The R terminal in VS Code is radian, not PowerShell, so neither file affects it.
git
The global git configuration (~/.gitconfig) only holds my name and e-mail address (user.name, user.email) and the Git LFS filters that git lfs install adds:
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = <your name>
email = <your e-mail>Everything else about git (autofetch, no sync confirmation, PR branches) is in the VS Code settings.
PATH rules
Most of my R-in-VS-Code problems have come from PATH. The rules:
| Rule | Why |
|---|---|
C:\Program Files\R\bin (rig’s shortcuts) is on PATH. |
R, Rscript and radian then use rig’s default version. |
No version folder such as C:\Program Files\R\R-x.y.z\bin on PATH. |
It pins one R version and overrides rig. |
No R_HOME environment variable (check both user and system). |
Same: radian and R use it before anything else. |
Python312\ and Python312\Scripts\ come before any other Python. |
python and radian must be the 3.12 ones. |
C:\Program Files\Quarto\bin is the only Quarto on PATH. |
R, VS Code and the terminal then use the same Quarto. |
| After any change: quit and restart VS Code. | VS Code and its terminals keep the PATH they started with. |
To check what a new process will see, without restarting anything:
$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
[Environment]::GetEnvironmentVariable("Path", "User")
Get-Command R.exe, python, radian, quarto | Select-Object Name, Source
[Environment]::GetEnvironmentVariable("R_HOME", "User")
[Environment]::GetEnvironmentVariable("R_HOME", "Machine")
radian --versionPackage libraries
Each R version (major.minor) has its own user library, %LOCALAPPDATA%\R\win-library\<x.y>. R 4.5.x versions share win-library\4.5; a new minor version starts with an empty library. That is why the R packages are installed once per R version.