| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,129 @@ |
| 1 |
+# Title: .Rprofile |
|
| 2 |
+# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
|
| 3 |
+# Version: 0.0 |
|
| 4 |
+# Created in: 2014-07-06 |
|
| 5 |
+# Modified in: |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+#==========# |
|
| 10 |
+# Comments # |
|
| 11 |
+#==========# |
|
| 12 |
+ |
|
| 13 |
+# ~/.Rprodile: executed by R for interactive shells. |
|
| 14 |
+# see http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+ |
|
| 18 |
+#==========# |
|
| 19 |
+# Versions # |
|
| 20 |
+#==========# |
|
| 21 |
+ |
|
| 22 |
+# v0.0 - 2014-07-06: creation |
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+#=======================# |
|
| 27 |
+# User specific options # |
|
| 28 |
+#=======================# |
|
| 29 |
+ |
|
| 30 |
+# Test if it is an interactive session |
|
| 31 |
+if(interactive()) |
|
| 32 |
+ |
|
| 33 |
+# Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace |
|
| 34 |
+.startup <- new.env() |
|
| 35 |
+ |
|
| 36 |
+# Don't ask me for my CRAN mirror every time |
|
| 37 |
+options("repos" = c(CRAN = "http://cran.revolutionanalytics.com"))
|
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+ |
|
| 41 |
+#===========# |
|
| 42 |
+# Functions # |
|
| 43 |
+#===========# |
|
| 44 |
+ |
|
| 45 |
+# Check if pacakge is installed |
|
| 46 |
+# source: http://r.789695.n4.nabble.com/test-if-a-package-is-installed-td1750671.html |
|
| 47 |
+require(utils, quietly = TRUE) |
|
| 48 |
+.startup$is.installed <- function(mypkg) {is.element(mypkg, installed.packages()[,1])}
|
|
| 49 |
+ |
|
| 50 |
+ |
|
| 51 |
+# All functions executed when starting R |
|
| 52 |
+.First <- function() {
|
|
| 53 |
+ |
|
| 54 |
+ # First message |
|
| 55 |
+ cat(" Welcome to R!\n\n")
|
|
| 56 |
+ |
|
| 57 |
+ # Add colors to prompt |
|
| 58 |
+ options(colorout.anyterm = TRUE) |
|
| 59 |
+ if(! .startup$is.installed("colorout")) {
|
|
| 60 |
+ cat("If you want colored prompt, you should install the colorout package.\nLink: http://www.lepem.ufc.br/jaa/colorout.html\n\n")
|
|
| 61 |
+ } else {
|
|
| 62 |
+ library('colorout')
|
|
| 63 |
+ setOutputColors256( |
|
| 64 |
+ normal = 40, |
|
| 65 |
+ number = 214, |
|
| 66 |
+ string = 85, |
|
| 67 |
+ const = 35, |
|
| 68 |
+ stderror = 45, |
|
| 69 |
+ error = c(1, 0, 1), |
|
| 70 |
+ warn = c(1, 0, 100) |
|
| 71 |
+ ) |
|
| 72 |
+ cat("\n")
|
|
| 73 |
+ } |
|
| 74 |
+ |
|
| 75 |
+ # Enlarge columns display in R terminal |
|
| 76 |
+ # source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
|
| 77 |
+ wideScreen <- function(howWide=Sys.getenv("COLUMNS")) {
|
|
| 78 |
+ options(width=as.integer(howWide)) |
|
| 79 |
+ wideScreen() |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+} |
|
| 83 |
+ |
|
| 84 |
+ |
|
| 85 |
+# All functions executed when exiting R |
|
| 86 |
+.Last <- function() {
|
|
| 87 |
+ if (! any(commandArgs() == '--no-readline')) {
|
|
| 88 |
+ require(utils, quietly=TRUE) |
|
| 89 |
+ #timestamp(quiet=TRUE) |
|
| 90 |
+ try(savehistory(Sys.getenv("R_HISTFILE")))
|
|
| 91 |
+ } |
|
| 92 |
+} |
|
| 93 |
+ |
|
| 94 |
+ |
|
| 95 |
+# Prompt showing current clock |
|
| 96 |
+# source: http://stackoverflow.com/questions/4222476/r-display-a-time-clock-in-the-r-command-line |
|
| 97 |
+myprompt <- "%H:%M R> " |
|
| 98 |
+if (capabilities()[["tcltk"]] && require(tcltk2, quietly=TRUE)) {
|
|
| 99 |
+ # First way |
|
| 100 |
+ .startup$updatePrompt <- function(...) {options(prompt=format(Sys.time(),myprompt))}
|
|
| 101 |
+ tclTaskSchedule(1000, .startup$updatePrompt(), id = "ticktock", redo = TRUE) |
|
| 102 |
+ .startup$updatePrompt() |
|
| 103 |
+} else {
|
|
| 104 |
+ # Second way: working except when error message (no time update) |
|
| 105 |
+ .startup$updatePrompt <- function(..., quietly=FALSE) {
|
|
| 106 |
+ options(prompt=format(Sys.time(),myprompt)) |
|
| 107 |
+ if (quietly == FALSE) {return(TRUE)}
|
|
| 108 |
+ } |
|
| 109 |
+ addTaskCallback(.startup$updatePrompt) |
|
| 110 |
+ .startup$updatePrompt(quietly=TRUE) |
|
| 111 |
+} |
|
| 112 |
+ |
|
| 113 |
+ |
|
| 114 |
+# Exit |
|
| 115 |
+.startup$bye <- function () {q("no")}
|
|
| 116 |
+ |
|
| 117 |
+ |
|
| 118 |
+ |
|
| 119 |
+#=========# |
|
| 120 |
+# Aliases # |
|
| 121 |
+#=========# |
|
| 122 |
+ |
|
| 123 |
+# Moving (bash-like command) |
|
| 124 |
+.startup$cd <- setwd |
|
| 125 |
+.startup$pwd <- getwd |
|
| 126 |
+ |
|
| 127 |
+ |
|
| 128 |
+# Attach all the variables above |
|
| 129 |
+attach(.startup) |