-
-
Save danielecook/8f1883c4f9f6e05797881d8b83ccf33f to your computer and use it in GitHub Desktop.
My .Rprofile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Loading R Profile") | |
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 | |
# Output dataframe to excel | |
.env$excel <- function(df) { | |
f <- paste0(tempdir(),'/', make.names(deparse(substitute(df))),'.',paste0(sample(letters)[1:5],collapse=""), '.csv') | |
write.csv(df,f) | |
system(sprintf("open -a 'Microsoft Excel' %s",f)) | |
} | |
## Read data on clipboard. | |
.env$clipboard <- function(...) { | |
ismac <- Sys.info()[1]=="Darwin" | |
if (!ismac) read.table(file="clipboard", ...) | |
else read.table(pipe("pbpaste"), ...) | |
} | |
## Open Finder to the current directory on mac | |
.env$macopen <- function(...) if(Sys.info()[1]=="Darwin") system("open .") | |
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment