Last active
August 6, 2016 20:11
-
-
Save ConradStack/33f0675b2ef0b1dddbf646aff9e2022f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Template for ~/.Rprofile script | |
| # environmental variables: | |
| Sys.setenv( | |
| AUTHOR="Conrad Stack", | |
| EMAIL="conrad.stack@someserver.com" | |
| ) | |
| # options(): | |
| options("stringsAsFactors"=FALSE) | |
| options(max.print=1000) | |
| options(scipen=1) | |
| # Turn on tab-completion for packages | |
| utils::rc.settings(ipck=TRUE) | |
| # Change default behavior of q() to not save | |
| q <- function (save="no", ...) { | |
| quit(save=save, ...) | |
| } | |
| ## Create a new invisible environment for all the functions to go in so it doesn't clutter your workspace. | |
| .env <- new.env() | |
| ## 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 | |
| } | |
| ## 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 .") | |
| ## Show the first 5 rows and first 5 columns of a data frame or matrix | |
| .env$hh <- function(d,n=5) if(class(d)=="matrix"|class(d)=="data.frame") d[1:n,1:n] | |
| ## Return the number of unique elements in x | |
| .env$n.unique <- function(x){ | |
| length(unique(x)) | |
| } | |
| ## Return the indices of the top n elements from numeric vector, vect | |
| .env$which.high <- function(vect, n=5){ | |
| thresh = min(head(sort(vect,decreasing=TRUE),n)) | |
| which(vect >= thresh) | |
| } | |
| ## Return the indices of the bottom n elements from numeric vector, vect | |
| .env$which.low <- function(vect, n=5){ | |
| thresh = min(head(sort(vect,decreasing=TRUE),n)) | |
| which(vect >= thresh) | |
| } | |
| ## Return the indices of the elements containing NA | |
| .env$which.na <- function(vect) which(is.na(vect)) | |
| ## Load cacao genome packages | |
| .env$load.genomes <- function(.criollo=FALSE){ | |
| library("BSgenome.Tcacao.MarsInc.v11") | |
| library("TxDb.Tcacao.Geneious.pub3i") | |
| if(.criollo) library("BSgenome.Tcacao.CIRAD.v10") | |
| } | |
| ## Attach all the variables above | |
| attach(.env) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(TODO) Need to come up with an easy way to install these on windows machines