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)
## put something this is your .Rprofile to customize the defaults
function(...) grDevices::X11.options(width=8, height=8,
#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
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.site and dito for
Rprofile, you appreciate the consistent behaviour across platforms.
Make sure all default packages are loaded before running .Rprofile
?Startup seems pretty definitive:
Note that when the site and user profile files are sourced only
the 'base' package is loaded, so objects in other packages need to
be referred to by e.g. 'utils::dump.frames' or after explicitly
loading the package concerned.
Based on that explicit recommendation, using
library() to load the necessary packages looks like your best bet.
How do I always show the line number of the error in R?
Add the option to your user specific .Rprofile file
options(show.error.locations = TRUE)
You can find the folder in which your user specific .Rprofile file should be using this function:
If a .Rprofile file does not already exist here, create it.
Where in R do I permanently store my custom functions?
Yes, create a package. There are numerous tutorials as well as the Writing R Extensions manual that came with your copy of R.
It may seem like too much work at first, but you will probably be glad that you did this in the longer run.
PS And you can then load that package from
~/.Rprofile. For really short code, you can also define it there.