My .Rprofile
always runs twice. I looked at this thread
and think it might be because the slashes are going in various directions.
I only have code in the paths pointing at C:/Users/rileyj3/.Rprofile
(results 1, 2 & 4). Does anyone know how to resolve?
expr | path | exists |
---|---|---|
file.path(getwd(), ".Rprofile") | C:/Users/rileyj3/.Rprofile | TRUE |
file.path(Sys.getenv("HOME"), ".Rprofile") | C:\Users\rileyj3/.Rprofile | TRUE |
file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site") | C:/PROGRA~1/R/R-42~1.2/etc/Rprofile.site | TRUE |
Sys.getenv("R_PROFILE") | C:\Users\rileyj3.Rprofile | TRUE |
Sys.getenv("R_PROFILE_USER") | FALSE |
library(tidyverse)
tibble(
expr = c(
'file.path(getwd(), ".Rprofile")',
'file.path(Sys.getenv("HOME"), ".Rprofile")',
'file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site")',
'Sys.getenv("R_PROFILE")',
'Sys.getenv("R_PROFILE_USER")'
)
) |>
mutate(
path = map_chr(expr, ~parse(text = .x) |> eval()),
exists = file.exists(path)
) |>
knitr::kable()
CodePudding user response:
You can see the details of R read Rprofile files on the ?Startup
help page.
R will look for both a site-wide and user-specific profile. Since you have a value set for R_PROFILE, that's considered a site-wide profile so it's run. Then when R looks for a user-specific value, it finds the one in your home directory so it runs that one as well. R doesn't check to see if the site-wide and specific files are the same. You should probably remove the R_PROFILE system environment variable since you seem to be setting a user-specific values there or move it to R_PROFILE_USER.