-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRprofile
94 lines (82 loc) · 2.89 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
options(width = 600) # wide display with multiple monitors
options(digits.secs = 3) # show sub-second time stamps
options(useFancyQuotes = FALSE)
options(datatable.print.class = TRUE)
options(datatable.print.keys = TRUE)
options(repos = c(REPO_NAME =
"https://packagemanager.posit.co/cran/latest"))
# "https://packagemanager.rstudio.com/all/__linux__/jammy/latest"))
options(languageserver.formatting_style = function(options) {
styler::tidyverse_style(scope = "indention", indent_by = options$tabSize)
})
r_lib <- file.path(Sys.getenv("HOME"), ".R",
paste0(R.Version()$major, ".", R.Version()$minor))
if (!dir.exists(r_lib)) dir.create(r_lib)
.libPaths(c(r_lib, .libPaths()))
Sys.setenv(R_LIBS_USER = r_lib)
rm(r_lib)
Sys.setenv(R_HISTSIZE = "100000")
if (Sys.getenv("R_HISTFILE") == "") {
Sys.setenv(R_HISTFILE = file.path("~", ".Rhistory"))
}
## Create a new invisible environment for all the functions to go in
# so it doesn't clutter your workspace.
.env <- new.env()
.env$o <- function(...) if (Sys.info()[1] == "Darwin") system("open .")
.env$cd <- setwd
.env$pwd <- getwd
.env$lss <- dir
.env$s <- base::summary
.env$h <- utils::head
## Show the first 5 rows and first 5 columns of a data frame or matrix
.env$hh <- function(d) if (class(d) %in% c("matrix", "data.frame")) d[1:5, 1:5]
## Read data on clipboard.
.env$read.cb <- function(...) {
ismac <- Sys.info()[1] == "Darwin"
if (!ismac) read.table(file = "clipboard", ...)
else read.table(pipe("pbpaste"), ...)
}
## List objects and classes (from @_inundata, mod by ateucher)
.env$lsa <- function() {
obj_type <- function(x) class(get(x, envir = .GlobalEnv)) # define environment
foo <- data.frame(sapply(ls(envir = .GlobalEnv), obj_type))
foo$object_name <- rownames(foo)
names(foo)[1] <- "class"
names(foo)[2] <- "object"
return(unrowname(foo))
}
## List all functions in a package (also from @_inundata)
.env$lsp <- function(package, all.names = FALSE, pattern) {
package <- deparse(substitute(package))
ls(pos = paste("package", package, sep = ":"), all.names = all.names,
pattern = pattern)
}
## Attach all the variables above
attach(.env)
options(error = function() {
calls <- sys.calls()
if (length(calls) >= 2L) {
sink(stderr())
on.exit(sink(NULL))
cat("Backtrace:\n")
calls <- rev(calls[-length(calls)])
for (i in seq_along(calls)) {
cat(i, ": ", deparse(calls[[i]], nlines = 1L), "\n", sep = "")
}
}
if (!interactive()) {
message("Exiting on error")
q(status = 1)
}
})
Sys.setenv(TERM_PROGRAM = "vscode")
source(file.path(Sys.getenv("HOME"), ".vscode-R", "init.R"))
if (interactive() && Sys.getenv("TERM_PROGRAM") == "vscode") {
if ("httpgd" %in% .packages(all.available = TRUE)) {
options(vsc.plot = FALSE)
options(device = function(...) {
httpgd::hgd()
.vsc.browser(httpgd::hgd_url(), viewer = "Beside")
})
}
}