Browse code

Rprofile - v0.4 - Avoid R crashing with X11

Fred authored on02/10/2016 14:47:03
Showing1 changed files
... ...
@@ -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