Category: Interface

Customize Startup

No Comments

There are a lot of ways you can customize the R startup. To begin with I kept it simple as highlighted in blue. The customization can be done via the initialization file called R always sources this file first and is found under the install directory’s \etc folder. I’ve added two functions .First() and .Last(). .First() executes at the start of the R session and .Last() executes at the end of the session. The changes made to the as below.

# Things you might want to change

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")

# set a site library
# <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
#       r["CRAN"] <- "http://my.local.cran"
#       options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
#  if (interactive())
#    fortunes::fortune()

.First <- function(){
cat("\nWelcome at", date(), "\n")
cat("\nYour Current Working Directory is:", getwd(), "\n")

.Last <- function(){
cat("\nGoodbye at ", date(), "\n")


No Comments

The Workspace is the R working environment which contains, user-defined objects. The object can be lists, vectors, matrices, data frames, functions.

Note: The following are the different ways to specify the path on Windows –

    # R Accepts Unix style path specification as below


    #R sees a single back slash as an escape character, hence for Windows style specification you needs to specify the path as below


The following are the list of commands to manage your workspace. As you enter the commands you can use the Up and Down arrow keys to scroll through the command history.


      1. getwd()                                     # Get current working directory
      2. setwd(“C:/RWorkspace”)           # Set current working directory
      3. ls()                                            # List the objects in the current workspace
      4. help(“ggplot2”)                         # Display info on the search string. In this case ggplot2.

    5. options()                                   # Display the options set for the current session

    6. history()                                    # Display last 25 commands

    7. history(             # Display all previous commands

    8. savehistory(file=”MyFile”)         # Default file is “.Rhistory”

    9. loadhistory(file=”MyFile”)          # Default file is “.Rhistory”

    10. save.image()                           # Save the workspace to the default “.RData”

    11. save(x,y, file=”MyFile.RData”) # Save specific object(s) to a file. “x” and “y” are objects

    12. load(“MyFile.RData”)               # Load the workspace into the current session

    13. library(“packagename”)          # Loads installed packages. For ex. ggplot2,  Rcmdr.

    14. q()                                           # Quit R with a prompt to save the workspace


    Note that R is case-sensitive, and assumes the current working directory if path is not specified.

Categories: Interface, Workspace

Quick Installation of R and R Commander on Windows

No Comments

The following is a quick four step installation for R and RCommander:

1. Download R for windows here.

2. To install R Commander, at the R command prompt issue the command:

      install.packages(‘Rcmdr’, dependencies=TRUE)

3. R Commander works best with single-document Rgui interface (SDI). Since the default installation is multiple-document interface (MDI), you can change the Rconsole file in R’s /etc directory to enable SDI. Look for the lines below in the file. 

     ## Style
    # This can be `yes’ (for MDI) or `no’ (for SDI).
    #MDI = yes
    MDI = no

4. To load R Commander issue the command at the R command prompt :