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
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.
Make sure all default packages are loaded before running .Rprofile
This, from ?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:
path.expand("~")
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.
Related Topics
How to Select Variables in an R Dataframe Whose Names Contain a Particular String
How to Add a Diagonal Line to a Plot
How to Join (Merge) Data Frames (Inner, Outer, Left, Right)
Why Are These Numbers Not Equal
Split Comma-Separated Strings in a Column into Separate Rows
R Markdown - Changing Font Size and Font Type in HTML Output
Removing Space Between Numeric Values in R
Remove Unwanted Symbols from Expression Function - R
R - Getting Characters After Symbol
Calculate Row Means on Subset of Columns
Duplicate Columns in Spark Dataframe
Combine Two Lists in a Dataframe in R
Filter Data.Frame Rows by a Logical Condition
Plotting Two Variables as Lines Using Ggplot2 on the Same Graph
How to Find the Difference in Value in Every Two Consecutive Rows in R
Divide All Columns by the Value from the 2Nd Column - Apply for All Rows
Generate List of All Possible Combinations of Elements of Vector