###################################################
### chunk number 1: setup
###################################################
#line 17 "EfficientR.Rnw"
options(width = 40)


###################################################
### chunk number 2: io-sketch eval=FALSE
###################################################
## #line 48 "EfficientR.Rnw"
## colClasses <-
##   c("NULL", "integer", "numeric", "NULL")
## df <- read.table("myfile", colClasses=colClasses)


###################################################
### chunk number 3: preallocate-and-fill-sketch eval=FALSE
###################################################
## #line 55 "EfficientR.Rnw"
## result <- numeric(nrow(df))
## for (i in seq_len(nrow(df)))
##   result[[i]] <- some_calc(df[i,])


###################################################
### chunk number 4: iterative
###################################################
#line 62 "EfficientR.Rnw"
x <- runif(100000); x2 <- x^2
m <- matrix(x2, nrow=1000); y <- rowSums(m)


###################################################
### chunk number 5: inappropriate-functions-2 eval=FALSE
###################################################
## #line 76 "EfficientR.Rnw"
## library(limma) # microarray linear models
## fit <- lmFit(eSet, design)


###################################################
### chunk number 6: algo-poly
###################################################
#line 82 "EfficientR.Rnw"
x <- 1:100; s <- sample(x, 10)
inS <- x %in% s


###################################################
### chunk number 7: system.time
###################################################
#line 101 "EfficientR.Rnw"
m <- matrix(runif(200000), 20000)
replicate(5, system.time(apply(m, 1, sum))[[1]])
replicate(5, system.time(rowSums(m))[[1]])


###################################################
### chunk number 8: identical
###################################################
#line 116 "EfficientR.Rnw"
res1 <- apply(m, 1, sum)
res2 <- rowSums(m)
identical(res1, res2)
identical(c(1, -1), c(x=1, y=-1))
all.equal(c(1, -1), c(x=1, y=-1),
          check.attributes=FALSE)


###################################################
### chunk number 9: Rprof eval=FALSE
###################################################
## #line 128 "EfficientR.Rnw"
## tmpf = tempfile()
## Rprof(tmpf)
## res1 <- apply(m,  1, sum)
## Rprof(NULL); summaryRprof(tmpf)


