RStudio environment customizations

Already in the first chapter, we showed you how to set up RStudio with the built-in settings so that it corresponds, practically and visually, with your wishes and preferences. But, there are also other options that cannot be set within the RStudio GUI since they are general R settings. An example of this is the Rprofile. But everything you determine in your personal Rprofile will also be executed in RStudio.

You may have never heard of the so-called Rprofile before. In fact, at first glance, it is just a normal text file, which can be found in the R home directory. But it could also be possible that you do not have such a file.

The customization of Rprofile is an interesting way to load personally stored functions, options, scripts, the preferred CRAN mirror, and so on, for your R sessions at every startup of R, respectively RStudio.

Since the possible features that you can integrate into your personal Rprofile are endless, in the following sections, we will discuss only a few examples.

Add a local CRAN mirror:

Easy debugging:

Preceding example is taken from: http://stackoverflow.com/posts/7107100/revisions.

Using aliases:

#ht==headtail, i.e., show the first and last 10 items of an object
ht <- function(d) rbind(head(d,10),tail(d,10))

# Show the first 5 rows and first 5 columns of a data frame or matrix
hh <- function(d) d[1:5,1:5]

Preceding example is taken from: http://stackoverflow.com/posts/8676073/revisions.

Set a proxy for your web requests:

Sys.setenv(http_proxy="http://XXX.xxx.x.xxx:xx/")

As already stated, you can almost define and set everything that you can imagine in your personal Rprofile. However, where a lot of light is, there is also shade. If you often collaborate with other people on R projects, or when you share your R scripts elsewhere, a big problem can arise with an intensely customized Rprofile: reproducibility. There can be several settings that you have added, which other users do not see, and your scripts may fail.

You can check this if you start R in your terminal with the command, --no-init-file. If your scripts are still working, you can share them without having to worry.