-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rprofile
168 lines (131 loc) · 5.44 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
## Emacs please make this -*- R -*-
## empty Rprofile.site for R on Debian
##
## Copyright (C) 2008 - 2018 Dirk Eddelbuettel and GPL'ed
##
## see help(Startup) for documentation on ~/.Rprofile and Rprofile.site
# ## Example of .Rprofile
# options(width=65, digits=5)
# options(show.signif.stars=FALSE)
# setHook(packageEvent('grDevices', 'onLoad'),
# function(...) grDevices::ps.options(horizontal=FALSE))
# set.seed(1234)
# .First <- function() cat("\n Welcome to R!\n\n")
## ======================== Micro Editor ===================================
## https://www.tecmint.com/micro-linuxtext-editor-with-syntax-highlighting/
## Micro – A Modern Terminal Based Text Editor with Syntax Highlighting
## ============================= PATH ======================================
#system('sudo chmod +rwx /usr/lib/R')
.pth <- .libPaths(c('/usr/lib/R/library', '/usr/lib/R/site-library'))
.libPaths(.pth)
#dir(paste0(R.home(component = 'home'), '/etc'))
## https://www.jumpingrivers.com/blog/customising-your-rprofile/
## -------------------------------------------------------------------------
## https://stackoverflow.com/a/13736073/3806250
# candidates <- c(Sys.getenv('R_PROFILE'),
# file.path(Sys.getenv('R_HOME'), 'etc', 'Rprofile.site'),
# Sys.getenv('R_PROFILE_USER'),
#file.path(getwd(), '.Rprofile') )
#
# Filter(file.exists, candidates)
## https://github.com/rstudio/reticulate/issues/496#issuecomment-601446838
#Sys.setenv(RETICULATE_PYTHON = '/usr/bin/python3')
#Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/bin/python')
## https://d.cosx.org/d/422269-r-410/11
Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/bin/python3',
'_R_USE_PIPEBIND_' = 'true')
#Sys.setenv(RETICULATE_PYTHON = '/home/englianhu/anaconda3/envs/py38/bin/python')
## -------------------------------------------------------------------------
## We set the cloud mirror, which is 'network-close' to everybody, as default
local({
r <- getOption('repos')
r['CRAN'] <- 'https://cloud.r-project.org'
options(repos = r)
})
## ======================== Load Packages ==================================
suppressPackageStartupMessages(require('utils'))
if(!suppressPackageStartupMessages(require('BBmisc'))) {
install.packages('BBmisc', dependencies = TRUE,
INSTALL_opts = '--no-lock')
}
suppressPackageStartupMessages(require('BBmisc'))
if(!suppressAll(require('devtools'))) {
install.packages('devtools', dependencies = TRUE,
INSTALL_opts = '--no-lock')
devtools::install_github('r-lib/devtools')
}
if(!suppressAll(require('startup'))) {
## https://github.com/HenrikBengtsson/startup
remotes::install_github('HenrikBengtsson/startup', ref = 'develop')
}
if(!suppressAll(require('Rdym'))) {
devtools::install_github('wrathematics/Rdym')
}
## https://www.jumpingrivers.com/blog/customising-your-rprofile/
if(!suppressAll(require('rprofile'))) {
remotes::install_github('csgillespie/rprofile')
}
if(!suppressAll(require('prompt'))) {
# Used for nice prompts
remotes::install_github('gaborcsardi/prompt')
}
if(!suppressAll(require('colorout'))) {
# Used for nice colours in the terminal; not for Windows
remotes::install_github('jalvesaq/colorout')
}
if(!suppressAll(require('tidyverse'))) {
devtools::install_github('tidyverse/tidyverse')
}
if(!suppressAll(require('lubridate'))) {
devtools::install_github('tidyverse/lubridate')
}
if(!suppressAll(require('prettycode'))) {
devtools::install_github('https://github.com/r-lib/prettycode')
}
#library(prettycode, exclude = c('!', 'print'))
pkgs <- c('MASS', 'devtools', 'lubridate', 'tidyverse', 'rprofile', 'prompt',
'colorout', 'Rdym', 'startup', 'conflicted', 'prettycode')
suppressAll(lib(pkgs))
rm(pkgs)
conflicted::conflict_prefer('print', 'base', quiet=TRUE)
## -------------------------------------------------------------------------
## https://stackoverflow.com/a/17486231/3806250
#.First()
.First <- function() {
Rdym::RdymEnable()
BBmisc::suppressAll(startup::install(path = '/home/englianhu'))
BBmisc::suppressAll(startup::startup(all = TRUE))
}
## ======================== Start Up =====================================
# A powerline clone, that also shows the system load average and the current working directory.
if (interactive()) prompt::set_prompt(prompt::new_prompt_powerline())
## https://www.jumpingrivers.com/blog/customising-your-rprofile/
if (interactive() && suppressAll(requireNamespace('rprofile'))) {
# Only useful if you use Makefiles
rprofile::create_make_functions()
# Startup options
rprofile::set_startup_options()
# Not RStudio console
if (rprofile::is_terminal()) {
# https://github.com/csgillespie/rprofile/blob/master/R/set-terminal.R
rprofile::set_terminal()
} else {
rprofile::set_rstudio()
}
.env = rprofile::set_functions()
suppressAll(attach(.env))
# Display wifi and no of R sessions
# Linux only
suppressWarnings(rprofile::set_startup_info())
}
## -------------------------------------------------------------------------
# Prints RStudio project on start-up
setHook('rstudio.sessionInit', function(newSession) {
active_rproj = rprofile::get_active_rproj()
if (!is.null(active_rproj)) {
base::message(glue::glue("{crayon::yellow('R-project:')} {active_rproj}"))
}
}, action = 'append')
#BBmisc::suppressAll(.First())
tryCatch(suppressWarnings(startup::startup(all = TRUE)), error=function(ex)
base::message('.Rprofile error: ', base::conditionMessage(ex)))