Expert R users, what's in your .Rprofile? [closed]

I have always found startup profile files of other people both useful and instructive about the language. Moreover, while I have some customization for Bash and Vim, I have nothing for R.

For example, one thing I always wanted is different colors for input and output text in a window terminal, and maybe even syntax highlighting.


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

options(stringsAsFactors=FALSE)

Although I don't actually have that in my .Rprofile, because it might breaks my coauthors' code, I wish it was the default. Why?

1) Character vectors use less memory (but only barely);

2) More importantly, we would avoid problems such as:

> x <- factor(c("a","b","c"))
> x
[1] a b c
Levels: a b c
> x <- c(x, "d")
> x
[1] "1" "2" "3" "d"

and

> x <- factor(c("a","b","c"))
> x[1:2] <- c("c", "d")
Warning message:
In `[<-.factor`(`*tmp*`, 1:2, value = c("c", "d")) :
  invalid factor level, NAs generated

Factors are great when you need them (e.g. implementing ordering in graphs) but a nuisance most of the time.


I hate to type the full words 'head', 'summary', 'names' every time, so I use aliases.

You can put aliases into your .Rprofile file, but you have to use the full path to the function (e.g. utils::head) otherwise it won't work.

# aliases
s <- base::summary
h <- utils::head
n <- base::names

EDIT: to answer your question, you can use the colorout package to have different colors in the terminal. Cool! :-)