# Title: .Rprofile # Author: Frédéric CHEVALIER # Version: 0.1 # Created in: 2014-07-06 # Modified in: 2014-08-06 #==========# # Comments # #==========# # ~/.Rprodile: executed by R for interactive shells. # see http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html #==========# # Versions # #==========# # v0.1 - 2014-08-06: bug correction about interactivity (curly brackets missing) # v0.0 - 2014-07-06: creation #=======================# # User specific options # #=======================# # Test if it is an interactive session if (interactive()) { # Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace .startup <- new.env() # Don't ask me for my CRAN mirror every time options("repos" = c(CRAN = "http://cran.revolutionanalytics.com")) #===========# # Functions # #===========# # Check if pacakge is installed # source: http://r.789695.n4.nabble.com/test-if-a-package-is-installed-td1750671.html require(utils, quietly = TRUE) .startup$is.installed <- function(mypkg) {is.element(mypkg, installed.packages()[,1])} # All functions executed when starting R .First <- function() { # First message cat(" Welcome to R!\n\n") # Add colors to prompt options(colorout.anyterm = TRUE) if(! .startup$is.installed("colorout")) { cat("If you want colored prompt, you should install the colorout package.\nLink: http://www.lepem.ufc.br/jaa/colorout.html\n\n") } else { library('colorout') setOutputColors256( normal = 40, number = 214, string = 85, const = 35, stderror = 45, error = c(1, 0, 1), warn = c(1, 0, 100) ) cat("\n") } # Enlarge columns display in R terminal # source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux wideScreen <- function(howWide=Sys.getenv("COLUMNS")) { options(width=as.integer(howWide)) wideScreen() } } # All functions executed when exiting R .Last <- function() { if (! any(commandArgs() == '--no-readline')) { require(utils, quietly=TRUE) #timestamp(quiet=TRUE) try(savehistory(Sys.getenv("R_HISTFILE"))) } } # Prompt showing current clock # source: http://stackoverflow.com/questions/4222476/r-display-a-time-clock-in-the-r-command-line myprompt <- "%H:%M R> " if (capabilities()[["tcltk"]] && require(tcltk2, quietly=TRUE)) { # First way .startup$updatePrompt <- function(...) {options(prompt=format(Sys.time(),myprompt))} tclTaskSchedule(1000, .startup$updatePrompt(), id = "ticktock", redo = TRUE) .startup$updatePrompt() } else { # Second way: working except when error message (no time update) .startup$updatePrompt <- function(..., quietly=FALSE) { options(prompt=format(Sys.time(),myprompt)) if (quietly == FALSE) {return(TRUE)} } addTaskCallback(.startup$updatePrompt) .startup$updatePrompt(quietly=TRUE) } # Exit .startup$bye <- function () {q("no")} #=========# # Aliases # #=========# # Moving (bash-like command) .startup$cd <- setwd .startup$pwd <- getwd # Attach all the variables above attach(.startup) } # End of interactive statement