-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rprofile
67 lines (54 loc) · 1.98 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
if (interactive()) {
pkgsToLoad=c('colorout', 'setwidth', 'vimcom')
for (pkg in pkgsToLoad) {
if (pkg %in% rownames(utils:::installed.packages())) {
library(pkg, character.only=T)
if (pkg == 'colorout') setOutputColors256(verbose=F)
pkgMsg = paste("Note: library", pkg, "loaded.")
} else {
pkgMsg = paste("Note: library", pkg, "is not installed.")
}
message(pkgMsg)
}
suppressWarnings(rm(pkgMsg, pkgsToLoad, pkg))
}
## Don't ask me for my CRAN mirror every time
options("repos" = c(CRAN = "http://cran.rstudio.com/"))
## Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace.
.env <- new.env()
## Returns a logical vector TRUE for elements of X not in Y
.env$"%nin%" <- function(x, y) !(x %in% y)
## Returns names(df) in single column, numbered matrix format.
.env$n <- function(df) matrix(names(df))
## Single character shortcuts for summary() and head().
.env$s <- base::summary
.env$h <- utils::head
## ht==headtail, i.e., show the first and last 10 items of an object
.env$ht <- function(d) rbind(head(d,10),tail(d,10))
## Show the first 5 rows and first 5 columns of a data frame or matrix
.env$hh <- function(d) if(class(d)=="matrix"|class(d)=="data.frame") d[1:5,1:5]
## Strip row names from a data frame (stolen from plyr)
.env$unrowname <- function(x) {
rownames(x) <- NULL
x
}
## List objects and classes (from @_inundata)
.env$lsa <- function() {
obj_type <- function(x) { class(get(x)) }
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)