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
library(MSnbase) | |
n <- 10000 | |
ll <- vector("list",length=n) | |
e <- new.env() | |
tl <- system.time(for (i in 1:n) | |
ll[[i]] <- new("Spectrum2")) | |
te <- system.time(for (i in 1:n) | |
assign(paste("X",i,sep=""),new("Spectrum2"),e)) | |
## Results for n=10000 |
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
m <- matrix(runif(1e6),nrow=10000) | |
## append to result vector -- slow | |
res1 <- NULL | |
t1 <- system.time(for (i in 1:1000) res1[i] <- sum(m[i,])) | |
## initialise to full length -- fast | |
res2 <- numeric(1000) | |
t2 <- system.time(for (i in 1:1000) res2[i] <- sum(m[i,])) |
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
## Credit Hadley Wickham | |
## http://www.mail-archive.com/r-help@r-project.org/msg125980.html | |
watch <- function(varname) { | |
old <- get(varname) | |
changed <- function(...) { | |
new <- get(varname) | |
if (!identical(old, new)) { | |
message(varname, " is now ", new) | |
old <<- new | |
} |
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
##' Return the name of variable \code{varname} in call \code{match_call}. | |
##' | |
##' @title Return a variable name | |
##' @param match_call An object of class \code{call}, as returned by \code{match.call}. | |
##' @param varname An \code{character} of length 1 which is looked up in \code{match_call}. | |
##' @return A \code{character} with the name of the variable passed as parameter | |
##' \code{varname} in parent close of \code{match_call}. |
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
scatterhist <- function(x, y, xlab="", ylab="", ...){ | |
zones <- matrix(c(2,0,1,3), ncol=2, byrow=TRUE) | |
layout(zones, widths=c(4/5,1/5), heights=c(1/5,4/5)) | |
xhist <- hist(x, plot=FALSE) | |
yhist <- hist(y, plot=FALSE) | |
top <- max(c(xhist$counts, yhist$counts)) | |
par(mar=c(3,3,1,1)) | |
plot(x,y, ...) | |
par(mar=c(0,3,1,1)) | |
barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0) |
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
> library(kernlab) | |
> data(iris) | |
> irismodel1 <- ksvm(Species ~ ., data = iris) | |
Using automatic sigma estimation (sigest) for RBF or laplace kernel | |
> irismodel2 <- ksvm(Species ~ ., data = iris) | |
Using automatic sigma estimation (sigest) for RBF or laplace kernel | |
> table(predict(irismodel1, iris[,-5]), predict(irismodel2, iris[,-5])) | |
setosa versicolor virginica | |
setosa 50 0 0 |
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
## http://gettinggeneticsdone.blogspot.co.uk/2012/09/deseq-vs-edger-comparison.html | |
library(DESeq) | |
library(edgeR) | |
library(VennDiagram) | |
# Read in data ------------------------------------------------------------ | |
## Use pasilla data | |
datafile = system.file( "extdata/pasilla_gene_counts.tsv", package="pasilla" ) |
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
getDependencies <- function(p, | |
rep = c("BioCsoft", "BioCann", "BioCexp", "BioCextra", "CRAN"), | |
biocVersion = "2.12", | |
depLevels = c("Depends", "Imports", "Suggests"), | |
filter = TRUE) { | |
rep <- match.arg(rep) | |
if (rep == "CRAN") { | |
rep <- getOption("repos")["CRAN"] | |
} else { | |
biocMirror <- getOption("BioC_mirror", "http://bioconductor.org") |
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
library(base64enc) | |
library(RJSONIO) | |
library(httr) | |
default_key <- function () { | |
key <- Sys.getenv("POSTMARKAPP_API_KEY") | |
if (key == "") { | |
stop("Either provide key or set envvar POSTMARKAPP_API_KEY", call. = FALSE) | |
} | |
key |
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
;; grep -h X-Key */*/cur/* | sed -e 's/X-Keywords: //; s/, /\n/g' | sort | uniq > xkeys.txt | |
(setq mu4e-xkeys "~/Maildir/xkeys.txt") | |
(defun read-lines (f) | |
"Return a list of lines of a file at f." | |
(with-temp-buffer | |
(insert-file-contents f) | |
(split-string (buffer-string) "\n" t))) |
OlderNewer