| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 1.0 |
|
| 3 |
+# Version: 1.1 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: 2020-03-01 |
|
| 5 |
+# Modified in: 2020-08-27 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v1.1 - 2020-08-27: reconnect_X11 function added / repo link updated |
|
| 22 | 23 |
# v1.0 - 2020-03-01: library path set / specific library path depending on the environment / section executed in non interactive mode / repo link updated |
| 23 | 24 |
# v0.4 - 2016-10-02: hour display on prompt simplified / auto-update of terminal column value for display added |
| 24 | 25 |
# v0.3 - 2014-11-03: less function added |
| ... | ... |
@@ -50,7 +51,7 @@ if (! .startup$is.root && ! .startup$is.conda) {
|
| 50 | 51 |
if (interactive()) {
|
| 51 | 52 |
|
| 52 | 53 |
# Don't ask me for my CRAN mirror every time |
| 53 |
-options("repos" = c(CRAN = "https://cran.revolutionanalytics.com"))
|
|
| 54 |
+options("repos" = c(CRAN = "https://cloud.r-project.org/"))
|
|
| 54 | 55 |
|
| 55 | 56 |
|
| 56 | 57 |
#===========# |
| ... | ... |
@@ -130,6 +131,15 @@ addTaskCallback(.startup$updatePrompt) |
| 130 | 131 |
file.show(file, delete.file = TRUE) |
| 131 | 132 |
} |
| 132 | 133 |
|
| 134 |
+# Reconnect to X11 |
|
| 135 |
+.startup$reconnect_X11 <- function(port) {
|
|
| 136 |
+ if (missing(port)) {
|
|
| 137 |
+ port <- system("xauth list | grep $(hostname) | tail -1 | awk '{print $1}' | sed \"s/.*://\"", intern = TRUE)
|
|
| 138 |
+ } |
|
| 139 |
+ Sys.setenv(DISPLAY = paste0("localhost:", port, ".0"))
|
|
| 140 |
+} |
|
| 141 |
+ |
|
| 142 |
+ |
|
| 133 | 143 |
|
| 134 | 144 |
|
| 135 | 145 |
#=========# |
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 0.4 |
|
| 3 |
+# Version: 1.0 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: 2016-10-02 |
|
| 5 |
+# Modified in: 2020-03-01 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -10,7 +10,7 @@ |
| 10 | 10 |
# Comments # |
| 11 | 11 |
#==========# |
| 12 | 12 |
|
| 13 |
-# ~/.Rprodile: executed by R for interactive shells. |
|
| 13 |
+# ~/.Rprofile: executed by R for interactive shells. |
|
| 14 | 14 |
# see http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html |
| 15 | 15 |
|
| 16 | 16 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v1.0 - 2020-03-01: library path set / specific library path depending on the environment / section executed in non interactive mode / repo link updated |
|
| 22 | 23 |
# v0.4 - 2016-10-02: hour display on prompt simplified / auto-update of terminal column value for display added |
| 23 | 24 |
# v0.3 - 2014-11-03: less function added |
| 24 | 25 |
# v0.2 - 2014-10-21: bug correction about width of terminal |
| ... | ... |
@@ -31,15 +32,25 @@ |
| 31 | 32 |
# User specific options # |
| 32 | 33 |
#=======================# |
| 33 | 34 |
|
| 34 |
-# Test if it is an interactive session |
|
| 35 |
-if (interactive()) {
|
|
| 36 |
- |
|
| 37 |
-# Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace |
|
| 35 |
+# Create a new invisible environment for all the objects and functions to go in so it doesn't clutter the workspace |
|
| 38 | 36 |
.startup <- new.env() |
| 39 | 37 |
|
| 40 |
-# Don't ask me for my CRAN mirror every time |
|
| 41 |
-options("repos" = c(CRAN = "http://cran.revolutionanalytics.com"))
|
|
| 38 |
+# Determine environment |
|
| 39 |
+.startup$is.root <- system("id -u", intern=TRUE) == 0
|
|
| 40 |
+.startup$is.conda <- nchar(Sys.getenv("CONDA_PREFIX")) > 0
|
|
| 41 |
+ |
|
| 42 |
+# Specific package folder in user global environment only |
|
| 43 |
+if (! .startup$is.root && ! .startup$is.conda) {
|
|
| 44 |
+ .startup$mylib <- paste0("~/.R-libs/", version$major, ".", version$minor)
|
|
| 45 |
+ if (! dir.exists(.startup$mylib)) {dir.create(.startup$mylib, recursive=TRUE)}
|
|
| 46 |
+ .libPaths(.startup$mylib) |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+# Test if it is an interactive session and run the downstream code |
|
| 50 |
+if (interactive()) {
|
|
| 42 | 51 |
|
| 52 |
+# Don't ask me for my CRAN mirror every time |
|
| 53 |
+options("repos" = c(CRAN = "https://cran.revolutionanalytics.com"))
|
|
| 43 | 54 |
|
| 44 | 55 |
|
| 45 | 56 |
#===========# |
| ... | ... |
@@ -81,7 +92,7 @@ require(utils, quietly = TRUE) |
| 81 | 92 |
|
| 82 | 93 |
# All functions executed when exiting R |
| 83 | 94 |
.Last <- function() {
|
| 84 |
- if (! any(commandArgs() == '--no-readline')) {
|
|
| 95 |
+ if (! any(commandArgs() == '--no-readline') && ! .startup$is.root) {
|
|
| 85 | 96 |
require(utils, quietly=TRUE) |
| 86 | 97 |
#timestamp(quiet=TRUE) |
| 87 | 98 |
try(savehistory(Sys.getenv("R_HISTFILE")))
|
| ... | ... |
@@ -116,7 +127,7 @@ addTaskCallback(.startup$updatePrompt) |
| 116 | 127 |
file <- tempfile() |
| 117 | 128 |
sink(file); on.exit(sink()) |
| 118 | 129 |
print(x) |
| 119 |
- file.show(file, delete.file = T) |
|
| 130 |
+ file.show(file, delete.file = TRUE) |
|
| 120 | 131 |
} |
| 121 | 132 |
|
| 122 | 133 |
|
| ... | ... |
@@ -126,7 +137,7 @@ addTaskCallback(.startup$updatePrompt) |
| 126 | 137 |
#=========# |
| 127 | 138 |
|
| 128 | 139 |
# Moving (bash-like command) |
| 129 |
-.startup$cd <- setwd |
|
| 140 |
+.startup$cd <- setwd |
|
| 130 | 141 |
.startup$pwd <- getwd |
| 131 | 142 |
|
| 132 | 143 |
|
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 0.3 |
|
| 3 |
+# Version: 0.4 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: 2014-11-03 |
|
| 5 |
+# Modified in: 2016-10-02 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v0.4 - 2016-10-02: hour display on prompt simplified / auto-update of terminal column value for display added |
|
| 22 | 23 |
# v0.3 - 2014-11-03: less function added |
| 23 | 24 |
# v0.2 - 2014-10-21: bug correction about width of terminal |
| 24 | 25 |
# v0.1 - 2014-08-06: bug correction about interactivity (curly brackets missing) |
| ... | ... |
@@ -39,10 +40,6 @@ if (interactive()) {
|
| 39 | 40 |
# Don't ask me for my CRAN mirror every time |
| 40 | 41 |
options("repos" = c(CRAN = "http://cran.revolutionanalytics.com"))
|
| 41 | 42 |
|
| 42 |
-# Enlarge columns display in R terminal |
|
| 43 |
-# source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
|
| 44 |
-options(width=as.integer(system("stty -a | head -n 1 | awk '{print $7}' | sed 's/;//'", intern=TRUE)))
|
|
| 45 |
- |
|
| 46 | 43 |
|
| 47 | 44 |
|
| 48 | 45 |
#===========# |
| ... | ... |
@@ -94,21 +91,20 @@ require(utils, quietly = TRUE) |
| 94 | 91 |
|
| 95 | 92 |
# Prompt showing current clock |
| 96 | 93 |
# source: http://stackoverflow.com/questions/4222476/r-display-a-time-clock-in-the-r-command-line |
| 94 |
+# Don't use Tcl/Tk beacuse starting X11 leading to R crash when X11 connection is killed |
|
| 97 | 95 |
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) |
|
| 96 |
+.startup$updatePrompt <- function(..., quietly=FALSE) {
|
|
| 97 |
+ # Update time |
|
| 98 |
+ options(prompt=format(Sys.time(),myprompt)) |
|
| 99 |
+ |
|
| 100 |
+ # Update terminal column value for display in R terminal |
|
| 101 |
+ # source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
|
| 102 |
+ options(width=as.integer(system("stty -a | head -n 1 | awk '{print $7}' | sed 's/;//'", intern=TRUE)))
|
|
| 103 |
+ |
|
| 104 |
+ if (quietly == FALSE) {return(TRUE)}
|
|
| 111 | 105 |
} |
| 106 |
+addTaskCallback(.startup$updatePrompt) |
|
| 107 |
+.startup$updatePrompt(quietly=TRUE) |
|
| 112 | 108 |
|
| 113 | 109 |
|
| 114 | 110 |
# Exit |
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 0.2 |
|
| 3 |
+# Version: 0.3 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: 2014-10-21 |
|
| 5 |
+# Modified in: 2014-11-03 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v0.3 - 2014-11-03: less function added |
|
| 22 | 23 |
# v0.2 - 2014-10-21: bug correction about width of terminal |
| 23 | 24 |
# v0.1 - 2014-08-06: bug correction about interactivity (curly brackets missing) |
| 24 | 25 |
# v0.0 - 2014-07-06: creation |
| ... | ... |
@@ -113,6 +114,15 @@ if (capabilities()[["tcltk"]] && require(tcltk2, quietly=TRUE)) {
|
| 113 | 114 |
# Exit |
| 114 | 115 |
.startup$bye <- function () {q("no")}
|
| 115 | 116 |
|
| 117 |
+# Less emulation |
|
| 118 |
+# source: http://stackoverflow.com/questions/3503811/is-there-an-r-equivalent-to-the-bash-command-more |
|
| 119 |
+.startup$less <- function(x) {
|
|
| 120 |
+ file <- tempfile() |
|
| 121 |
+ sink(file); on.exit(sink()) |
|
| 122 |
+ print(x) |
|
| 123 |
+ file.show(file, delete.file = T) |
|
| 124 |
+} |
|
| 125 |
+ |
|
| 116 | 126 |
|
| 117 | 127 |
|
| 118 | 128 |
#=========# |
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 0.1 |
|
| 3 |
+# Version: 0.2 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: 2014-08-06 |
|
| 5 |
+# Modified in: 2014-10-21 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v0.2 - 2014-10-21: bug correction about width of terminal |
|
| 22 | 23 |
# v0.1 - 2014-08-06: bug correction about interactivity (curly brackets missing) |
| 23 | 24 |
# v0.0 - 2014-07-06: creation |
| 24 | 25 |
|
| ... | ... |
@@ -37,6 +38,10 @@ if (interactive()) {
|
| 37 | 38 |
# Don't ask me for my CRAN mirror every time |
| 38 | 39 |
options("repos" = c(CRAN = "http://cran.revolutionanalytics.com"))
|
| 39 | 40 |
|
| 41 |
+# Enlarge columns display in R terminal |
|
| 42 |
+# source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
|
| 43 |
+options(width=as.integer(system("stty -a | head -n 1 | awk '{print $7}' | sed 's/;//'", intern=TRUE)))
|
|
| 44 |
+ |
|
| 40 | 45 |
|
| 41 | 46 |
|
| 42 | 47 |
#===========# |
| ... | ... |
@@ -73,13 +78,6 @@ require(utils, quietly = TRUE) |
| 73 | 78 |
cat("\n")
|
| 74 | 79 |
} |
| 75 | 80 |
|
| 76 |
- # Enlarge columns display in R terminal |
|
| 77 |
- # source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
|
| 78 |
- wideScreen <- function(howWide=Sys.getenv("COLUMNS")) {
|
|
| 79 |
- options(width=as.integer(howWide)) |
|
| 80 |
- wideScreen() |
|
| 81 |
- } |
|
| 82 |
- |
|
| 83 | 81 |
} |
| 84 | 82 |
|
| 85 | 83 |
|
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 | 1 |
# Title: .Rprofile |
| 2 | 2 |
# Author: Frédéric CHEVALIER <f15.chevalier@gmail.com> |
| 3 |
-# Version: 0.0 |
|
| 3 |
+# Version: 0.1 |
|
| 4 | 4 |
# Created in: 2014-07-06 |
| 5 |
-# Modified in: |
|
| 5 |
+# Modified in: 2014-08-06 |
|
| 6 | 6 |
|
| 7 | 7 |
|
| 8 | 8 |
|
| ... | ... |
@@ -19,6 +19,7 @@ |
| 19 | 19 |
# Versions # |
| 20 | 20 |
#==========# |
| 21 | 21 |
|
| 22 |
+# v0.1 - 2014-08-06: bug correction about interactivity (curly brackets missing) |
|
| 22 | 23 |
# v0.0 - 2014-07-06: creation |
| 23 | 24 |
|
| 24 | 25 |
|
| ... | ... |
@@ -28,7 +29,7 @@ |
| 28 | 29 |
#=======================# |
| 29 | 30 |
|
| 30 | 31 |
# Test if it is an interactive session |
| 31 |
-if(interactive()) |
|
| 32 |
+if (interactive()) {
|
|
| 32 | 33 |
|
| 33 | 34 |
# Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace |
| 34 | 35 |
.startup <- new.env() |
| ... | ... |
@@ -56,11 +57,11 @@ require(utils, quietly = TRUE) |
| 56 | 57 |
|
| 57 | 58 |
# Add colors to prompt |
| 58 | 59 |
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( |
|
| 60 |
+ if(! .startup$is.installed("colorout")) {
|
|
| 61 |
+ cat("If you want colored prompt, you should install the colorout package.\nLink: http://www.lepem.ufc.br/jaa/colorout.html\n\n")
|
|
| 62 |
+ } else {
|
|
| 63 |
+ library('colorout')
|
|
| 64 |
+ setOutputColors256( |
|
| 64 | 65 |
normal = 40, |
| 65 | 66 |
number = 214, |
| 66 | 67 |
string = 85, |
| ... | ... |
@@ -69,13 +70,13 @@ require(utils, quietly = TRUE) |
| 69 | 70 |
error = c(1, 0, 1), |
| 70 | 71 |
warn = c(1, 0, 100) |
| 71 | 72 |
) |
| 72 |
- cat("\n")
|
|
| 73 |
+ cat("\n")
|
|
| 73 | 74 |
} |
| 74 | 75 |
|
| 75 |
- # Enlarge columns display in R terminal |
|
| 76 |
+ # Enlarge columns display in R terminal |
|
| 76 | 77 |
# source: http://stackoverflow.com/questions/1172485/how-to-increase-the-number-of-columns-using-r-in-linux |
| 77 | 78 |
wideScreen <- function(howWide=Sys.getenv("COLUMNS")) {
|
| 78 |
- options(width=as.integer(howWide)) |
|
| 79 |
+ options(width=as.integer(howWide)) |
|
| 79 | 80 |
wideScreen() |
| 80 | 81 |
} |
| 81 | 82 |
|
| ... | ... |
@@ -127,3 +128,5 @@ if (capabilities()[["tcltk"]] && require(tcltk2, quietly=TRUE)) {
|
| 127 | 128 |
|
| 128 | 129 |
# Attach all the variables above |
| 129 | 130 |
attach(.startup) |
| 131 |
+ |
|
| 132 |
+} # End of interactive statement |
| 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) |