Installing and customizing R

Installing R isn’t difficult, but tweaking it to fit your own needs might need a bit of explanation. We can’t cover all possibilities here, so be sure to read the information on the R website for more insight on how to install and configure the software.

Installing R

You can find the installation files and all necessary information regarding installation at the Comprehensive R Archive Network, or CRAN. Follow the link for your operating system.

Mac OS X and Linux users especially need to read the instructions on the CRAN site carefully. R can be installed on all systems, but depending on your version of OS X or Linux, you may need to follow special procedures to install R successfully. Note that R comes pre-installed in Debian-derived flavours of Linux (including Ubuntu), so you don’t have to install anything, other than a code editor, such as RStudio.

Configuring R

Apart from accepting the options in the installation procedure, you can personalize R further by adapting the

Rprofile.site 

 file. This file is located inside the installation directory, in the subfolder

…/R-n.n.n/etc

. The file is sourced by R at startup, so everything in this file is carried out. It is a normal text file, so it can be edited like any other text file. The file contains already some options that are commented out, so you get a fair idea of what is possible there when you open the file in a text editor.

You can use two special functions here:

.First()

and

.Last()

, which run at the start and end, respectively, of an R session. You can define these functions yourself in the

Rprofile.site

file, which might look something like this:

 
# Sample Rprofile.site file 
# R interactive prompt 
options(prompt="R > ")
# sets work directory back to original
go.home <- function() setwd('D:/MyWorkspace')
 
.First <- function(){
  cat("\n You started at ", date(), "\n") 
}
.Last <- function(){ 
  cat("\n You leave at ", date(), "\n")
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get the book.

Recent Comments
Archives
Categories