public
Last active

My .Rprofile

  • Download Gist
.Rprofile.r
R
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
## See http://gettinggeneticsdone.blogspot.com/2013/06/customize-rprofile.html
 
## Load packages
library(BiocInstaller)
 
## Don't show those silly significanct stars
options(show.signif.stars=FALSE)
 
## Do you want to automatically convert strings to factor variables in a data.frame?
## WARNING!!! This makes your code less portable/reproducible.
options(stringsAsFactors=FALSE)
 
## Get the sqldf package to play nicely on OSX. No longer necessary with R 3.0.0
## From http://stackoverflow.com/questions/8219747/sqldf-package-in-r-querying-a-data-frame
## options(sqldf.driver="SQLite")
# options(gsubfn.engine = "R")
 
## 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]
 
## Read data on clipboard.
.env$read.cb <- function(...) {
ismac <- Sys.info()[1]=="Darwin"
if (!ismac) read.table(file="clipboard", ...)
else read.table(pipe("pbpaste"), ...)
}
 
## Strip row names from a data frame (stolen from plyr)
.env$unrowname <- function(x) {
rownames(x) <- NULL
x
}
 
## 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
)
}
 
## Open Finder to the current directory on mac
.env$macopen <- function(...) if(Sys.info()[1]=="Darwin") system("open .")
.env$o <- function(...) if(Sys.info()[1]=="Darwin") system("open .")
 
## Attach all the variables above
attach(.env)
 
## .First() run at the start of every R session.
## Use to load commonly used packages?
.First <- function() {
# library(ggplot2)
cat("\nSuccessfully loaded .Rprofile at", date(), "\n")
}
 
## .Last() run at the end of the session
.Last <- function() {
# save command history here?
cat("\nGoodbye at ", date(), "\n")
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.