Start up

The .Rprofile file

When R starts up it will run

  1. the site-wide R start up configuration file

  2. .Rprofile in the current working directory (the directory where R is started on the command-line)

  3. If that file doesn't exist, it will then check your home directory

The .Rprofile file

Determine your home area:

path.expand("~")

We can again test whether this file exists using

file.exists("~/.Rprofile")

Ten Minute Task

Ten Minute Task

    path.expand("~")

to determine your home directory and

    file.exists("~/.Rprofile")

to see if you have an .Rprofile

    message("Today is ", Sys.Date())

Some Examples

Example .Rprofile settings

options(prompt = "R> ", # Exciting new R> prompt
        digits = 4, # No. of digits displayed
        show.signif.stars = FALSE, # I hate stars
        fix_width = 88, # Useful under Linux
        Ncpus = 6L, # Parallel package installation
        continue = " ", # Hide the `+`
        mc.cores = 6L) # Parallel (see later)

Setting the CRAN mirror

r = getOption("repos")             
r["CRAN"] = "https://cran.rstudio.com/"
options(repos = r)
rm(r)

Useful functions

setnicepar = function(mar = c(3, 3, 2, 1), mgp = c(2, 0.4, 0), 
    tck = -.01, cex.axis = 0.9, las = 1, mfrow = c(1, 1), ...) {
     par(mar = mar, mgp = mgp, tck = tck,
       cex.axis = cex.axis, las = las, mfrow = mfrow, ...)
     }

Useful functions

Useful functions

.obj = 1
ls()

Useful functions

This concept also works with environments. In our .Rprofile file we create a hidden environment

.env = new.env()

Then add our functions to the environment

.env$ht = function(d, n=6) rbind(head(d, n), tail(d, n))

At the end of the .Rprofile file, we use the attach()

attach(.env)


jr-packages/efficientTutorial documentation built on Feb. 16, 2020, 7:05 p.m.