-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rprofile
60 lines (52 loc) · 1.92 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
# COMMON R-profile
## I seem to need this to get graphics to work on Mac OS X
## disable if using jupyter r kernel to prevent flashing window
## options(device="quartz")
options("width"=120)
options(max.print = 2000)
## applies to emacs only
local({
r <- getOption("repos")
##r["CRAN"] <- "https://cran.cnr.berkeley.edu/"
r["CRAN"] <- "https://cran.rstudio.com/"
options(repos = r)
})
## utility functions (only used in R console)
h <- function(x) head(x)
g <- function(x) glimpse(x)
s <- function(x) summary(x)
l <- function(x) length(x)
u <- function(x) unique(x)
adf <- function(x) as.data.frame(x)
## lsos()
## https://github.com/nfultz/stackoverflow/blob/master/R/lsos.R
.ls.objects <- function (pos = 1, pattern, order.by,
decreasing=FALSE, head=FALSE, n=5) {
napply <- function(names, fn) sapply(names, function(x)
fn(get(x, pos = pos)))
names <- ls(pos = pos, pattern = pattern)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.mode <- napply(names, mode)
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
obj.prettysize <- napply(names, function(x) {
capture.output(print(object.size(x), units = "auto")) })
obj.size <- napply(names, object.size)
obj.dim <- t(napply(names, function(x)
as.numeric(dim(x))[1:2]))
vec <- is.na(obj.dim)[, 1] & (obj.type != "function")
obj.dim[vec, 1] <- napply(names, length)[vec]
out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim)
names(out) <- c("Type", "Size", "PrettySize", "Rows", "Columns")
if (!missing(order.by))
out <- out[order(out[[order.by]], decreasing=decreasing), ]
if (head)
out <- head(out, n)
out
}
# shorthand
lsos <- function(..., n=10) {
.ls.objects(...)
}
lsoss <- function(..., n=10) {
.ls.objects(..., order.by="Size", decreasing=TRUE, head=TRUE)
}