R 3.5.0 “Joy in playing” was released April 23rd this year. It took a couple of weeks before it was made available on Debian testing due to the work required to rebuild the packages and as a Debian user that spend a lot of time on R, I am extremely grateful to the work of Dirk, Michael and Johannes on this!
I thought it was a good opportunity to write few notes about my R setup. Nothing really special or tricky and I guess more advanced users proceed otherwise, yet it is nonetheless simple and functional 😄! In this post I’ll go over two different aspects:
- 
the way I install R and the packages I use,
 - 
how I customized my R’s startup.
 
How do I install and the package I use?
As mentioned in a previous post, I am
currently working on Debian testing and use apt-get to install my software
which includes R:
 | 
 | 
I use the default location to store the core packages, i.e. /usr/lib/R/library/.
After the installation of the core packages, I configure Java for R (see Java support on the manual for
more details):
 | 
 | 
Then I install all CRAN packages available via apt-get:
 | 
 | 
This actually is very helpful to ensure that dependencies are properly installed!
The path to those packages is /usr/lib/R/site-library/ (again default behavior)
It is true though that I do not use all these packages, but:
- 
I use a fair portion of them (directly or as dependencies of other packages I use)
 - 
It is really quick to install (quicker than installing them from inside R)
 - 
I have space on my computer and it only takes one single line on my script whereas a selection would probably have taken tens 😄!
 
For the remaining packages (not packaged specifically for Debian), I use the
classical ìnstall.packages() for packages on CRAN and devtools::install_github()
for GitHub packages. I do not use package from other repositories.
For those packages, I have created a small gist
to gather them and I edit it each time I’ve found a package relevant for my research.
In order to install this package I get the gist (an R script) and execute it:
 | 
 | 
The path to these packages is /home/kevcaz/R/x86_64-pc-linux-gnu-library/3.5
this is not the default behavior but a path commonly used. So, yes, in total
I use 3 different paths to my R packages 😃:
 | 
 | 
This is actually quite handful, especially to remember how a given package was installed:
 | 
 | 
Well, I very much like it that way 😸! Two notes to conclude this section.
First, in the near future I may consider
the neat drat package to add
packages available on GitHub. Second, if you are interested in
reproducing this installation, have a look at my installDebian.sh gist.
Now that R is installed let’s see how to customize the launch process.
My R’s Startup
When you type R and enter in your favorite terminal or when you open
RStudio, many things happen before you can enter your first line of code for
the session (even more for RStudio I guess). This is the startup process. It
is thoroughly explained here
(also available in R using help(Startup)) and in this post on R Views.
Below I’d like to explain how I take advantage of the possibility of
personalizing it to make my use of R more comfortable. Basically, during the
launch process I:
- set up a couple of options (including default packages loaded),
 - tweak some paths,
 - get nice hello and good bye messages (the most important part!).
 
For what I do, you simply must retain how to locate Renviron. First,
call R.home:
 | 
 | 
Renviron is in /etc,
so for me /usr/lib/R/etc:
 | 
 | 
Once you have opened it (it may require the super user mode though),
you’ll find many options you can change. I suggest you do not change
anything and rather add a new variable R_ENVIRON to point to a site file
where you will do the changes without touching the original file (well
this is actually the purpose of this variable). In my case I added:
R_ENVIRON = "/usr/lib/R/etc/Renviron.site"
It is not mandatory but it is pretty common to locate where you add your chnages
next to the default one. On Debian we actually get an empty Renviron.site file:
##                                              Emacs please make this -*- R -*-
## empty Renviron.site for R on Debian
##
## Copyright (C) 2008 - 2017  Dirk Eddelbuettel and GPL'ed
##
## see help(Startup) for documentation on ~/.Renviron and Renviron.site
# ## Example ~/.Renviron on Unix
# R_LIBS=~/R/library
# PAGER=/usr/local/bin/less
# ## Example .Renviron on Windows
# R_LIBS=C:/R/library
# MY_TCLTK="c:/Program Files/Tcl/bin"
# ## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
# R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
# # this loads the packages in the order given, so they appear on
# # the search path in reverse order.
## # We comment out this line in the default Renviron, you can re-enable it here
## # @R_PLATFORM@ can be eg x86_64-pc-linux-gnu, see /etc/R/Renviron for R_PLATFORM
## # @MAJ_MIN_VERSION@ is likely something like '3.4', see /etc/R/Renviron too
#R_LIBS_USER=${R_LIBS_USER-'~/R/@R_PLATFORM@-library/@MAJ_MIN_VERSION@'}
Thanks Dirk for this! As you can read, several changes are possible and all
the parameter found in Renviron may be used. In my case I added two lines
R_PROFILE_USER = "~/.Rprofile"
R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.5'}
The latter indicates the path to packages installed with ìnstall.packages(),
while the former points to another file where I do most of the tweaks!
Here it is (also available on
):
 | 
 |