-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rprofile
65 lines (65 loc) · 2.66 KB
/
Rprofile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.First = function() {
message_wrap <- function(...) {
message(paste(strwrap(paste(..., collapse=' ')), collapse='\n'))
}
wait_for_prepare_log <- function(newSession) {
if (file.exists('/tmp/.rstudio_environment'))
readRenviron('/tmp/.rstudio_environment')
current_env = Sys.getenv('CONDA_DEFAULT_ENV')
desired_env = Sys.getenv('CONDA_DESIRED_ENV')
fpath = '~/prepare.log'
cat('Active conda environment:', current_env, '\n')
if (!file.exists(fpath)) {
if (current_env == desired_env) {
message_wrap(
'NOTE: The project environment is still being prepared.',
'If you do not wish to wait, press RETURN then ESC to exit to',
'the command line; but note that some R packages may not yet',
'be available for use until this process is complete.')
} else {
message('Requested conda environment: ', desired_env)
message_wrap(
'NOTE: The requested environment is still being created. Once',
'this is complete, R will be restarted. If you do not wish to',
'wait, press RETURN then ESC to exit to the command line; but',
'note that you will then need to monitor the creation process',
'yourself, and restart R manually when it is complete.')
}
counter = 0
cat('Waiting...')
while (!file.exists(fpath)) {
Sys.sleep(0.2)
counter = counter + 1
if (counter == 15) {
counter = 0
cat('.')
flush.console()
}
}
cat('\n')
message('Environment preparation is complete.')
if (current_env != desired_env) {
message('Restarting R...')
.rs.api.restartSession()
}
} else if (desired_env == '@ERROR@') {
message_wrap(
'ERROR: an unexpected error prevented the startup script',
'from determining the desired conda environment. This is',
'typically caused by corruption in anaconda-project.yml.',
'Consult the file /opt/continuum/prepare.log for details.')
} else if (current_env != desired_env) {
message('Requested conda environment: ', desired_env)
message_wrap(
'ERROR: The project preparation stage is complete, but the',
'requested conda environment does not have an R interpreter.',
'This is either because the anaconda-project.yml file does',
'not specify an r-base package, or there was an error during',
'preparation. Consult the file /opt/continuum/prepare.log',
'for more details.')
}
}
if (Sys.getenv("RSTUDIO") == "1") {
setHook("rstudio.sessionInit", wait_for_prepare_log, action="append")
}
}