This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
/
.Rprofile
88 lines (75 loc) · 2.09 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
# Hardcode a https mirror.
.First <- function() {
options(
download.file.method = "libcurl",
repos = c(CRAN = "https://cran.rstudio.com/"),
max.print = 1000,
dplyr.print_max = 1000#,
# browserNLdisabled = TRUE
)
}
message(paste0("Version: ", version$major, ".",
version$minor, " ", version$status))
pkg <- utils::installed.packages()[, "Package"]
# Better yesno function from devtools
if (isTRUE("devtools" %in% pkg)) {
setHook(packageEvent("devtools", "onLoad"), {
yesno <- function(...) {
cat(paste0(..., collapse = ""))
utils::menu(c("Yes", "No")) != 1
}
utils::assignInNamespace("yesno", yesno, "devtools")
rm(yesno)
})
}
# Better ui_yeah function from usethis
if (isTRUE("usethis" %in% pkg)) {
setHook(packageEvent("devtools", "onLoad"), {
ui_yeah <- function(x, ...) {
cat(x)
utils::menu(c("Yes", "No"))
}
utils::assignInNamespace("ui_yeah", ui_yeah, "usethis")
rm(ui_yeah)
})
}
# Add rrelaxiv to drat repos
if (isTRUE("drat" %in% pkg)) {
setHook(packageEvent("drat", "onLoad"), {
drat::addRepo("rrelaxiv", "https://errickson.net/rrelaxiv")
})
}
# Load grinch library for means
# https://github.com/josherrickson/grinch
if (isTRUE("grinch" %in% pkg)) {
require(grinch, quietly = TRUE)
}
rm(pkg)
# Stick these in their own environment so that rm(list=ls()) doesn't
# kill them
attach(list(
table0 = function(...) { table(list(...), useNA='ifany') } ,
sum0 = function(...) { sum(..., na.rm=TRUE) } ,
mean0 = function(...) { mean(..., na.rm=TRUE) } ,
peek = function(x, n=3) {
if (is.null(dim(x))) {
n <- min(n, length(x)); return(x[1:n])
};
n <- min(n, dim(x)); x[1:n, 1:n]
},
round0 = function(x, digits=2, ...) {
if(!is.data.frame(x)) {
return(round(x, digits=digits, ...))
}
isnum <- sapply(x, is.numeric)
x[,isnum] <- round(x[,isnum], digits=digits, ...)
return(x)
},
logit = function (x) {
log(x/(1 - x))
},
invlogit = function (x) {
1/(1 + exp(-x))
}),
name = 'MyFunctions'
)