Locate the .Rprofile file generating default options
Like @Gsee suggested, ?Startup
has all you need. Note that there isn't just the user profile file, but also a site profile file you could have messed with. And that both files can be found in multiple locations.
You could run the following to list existing files on your system among those listed on the page:
candidates <- c( Sys.getenv("R_PROFILE"),
file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),
Sys.getenv("R_PROFILE_USER"),
file.path(getwd(), ".Rprofile"),
file.path(Sys.getenv("HOME"), ".Rprofile"))
Filter(file.exists, candidates)
Note that it should be run on a fresh session, right after your started R, so that getwd()
will return the current directory at startup. There is also the tricky possibility that your profile files do modify the current directory at startup, in which case you would have to start a "no-profile" session (run R --no-site-file --no-init-file
) before running the code above.
How to modify and save Rprofile.site under Windows?
You don't have write access to the program files folder. To get it on a temporary basis start Notepad++ as administrator from the right click menu of the shortcut you use to start it. Then you will be able to write this file.
Expert R users, what's in your .Rprofile?
Here is mine. It won't help you with the coloring but I get that from ESS and Emacs...
options("width"=160) # wide display with multiple monitors
options("digits.secs"=3) # show sub-second time stamps
r <- getOption("repos") # hard code the US repo for CRAN
r["CRAN"] <- "http://cran.us.r-project.org"
options(repos = r)
rm(r)
## put something this is your .Rprofile to customize the defaults
setHook(packageEvent("grDevices", "onLoad"),
function(...) grDevices::X11.options(width=8, height=8,
xpos=0, pointsize=10,
#type="nbcairo")) # Cairo device
#type="cairo")) # other Cairo dev
type="xlib")) # old default
## from the AER book by Zeileis and Kleiber
options(prompt="R> ", digits=4, show.signif.stars=FALSE)
options("pdfviewer"="okular") # on Linux, use okular as the pdf viewer
Sourcing in Rprofile.site: How to find the location of the sourced file
If you can't use absolute paths and that your working directory is not stable, one way is to use .libPaths
or .Library
.
By default your Rprofile
should be in directory paste0(.Library,"/../etc/")
or paste0(.libPaths()[2],"/etc/")
so you can put your file there and source it with :
source(paste0(.Library,"/../etc/my_settings.R"))
source(paste0(.libPaths()[2],"/etc/my_settings.R"))
As far as I understand the first option is stable (I don't think one can change the value of .Library
).
If you use the second option just make sure that if in the future you alter your .libPaths()
you do it after sourcing your file.
See ?.libPaths
for more info on default folders.
How can I modify the startup message in R? Where is the code with this message?
You could set a personal startup message for R (which also will show in RStudio) by adding a line with message()
in the .Rprofile
.
In my case, the .Rprofile
is in "My Documents" under Windows and is edited with the free tool Notepad++.
At the end of the file I have a line
### KoenV: Illustrate setting R startup message
message("I have changed my message")
The following appears when I start R
You can read more about accessing and editing this file in this post.
How to automatically load settings in R on OSX? How to find R_HOME, configure Rprofile.site, etc?
Over the years I have come to rely on the help(Startup)
documentation as the best place to read up on this. There are numerous per-user and per-site configuration file as is customary for rich applications. It may seem like overkill at first but it is a really good system. And once you grok Renviron
versus Renviron.site
and dito for Rprofile
, you appreciate the consistent behaviour across platforms.
Related Topics
How to Find Out Which Package Version Is Loaded in R
How to Set Fixed Continuous Colour Values in Ggplot2
Bigrams Instead of Single Words in Termdocument Matrix Using R and Rweka
Reason Behind Speed of Fread in Data.Table Package in R
Change Day of the Month in a Date to First Day (01)
Removing One Tablegrob When Applied to a Box Plot with a Facet_Wrap
Inputting Na Where There Are Missing Values When Scraping with Rvest
How to Nicely Annotate a Ggplot2 (Manual)
Suggestions for Speeding Up Random Forests
Reading Multiple CSV Files from a Folder into a Single Dataframe in R
Use Ggpairs to Create This Plot
Make Readline Wait for Input in R
How to Use Tidyr::Separate When the Number of Needed Variables Is Unknown
Setting Upper and Lower Limits in Rnorm
How to Use Data.Table Within Functions and Loops
Combine Several Data Frames in the Global Environment by Row (Rbind)