###################################################
### chunk number 1: setup0
###################################################
#line 37 "R_intro.Rnw"
options(width=70)


###################################################
### chunk number 2: selfDescribingEx
###################################################
#line 87 "R_intro.Rnw"
x <- data.frame(type=c(rep("case",2),rep("control",3)), 
                time=rnorm(5))
y <- 10
z <- "a string"
class(z)
class(x)


###################################################
### chunk number 3: vectors
###################################################
#line 105 "R_intro.Rnw"
v <- 123
s = "a string"
t <- TRUE
letters
length(letters)


###################################################
### chunk number 4: vectorsRepAndSeq
###################################################
#line 124 "R_intro.Rnw"
seq(1, 3) 
1:3
rep(1:2, 3)
vector(mode="character", length=5)


###################################################
### chunk number 5: vec1
###################################################
#line 141 "R_intro.Rnw"
1:3 + 10:12


###################################################
### chunk number 6: vec2
###################################################
#line 149 "R_intro.Rnw"
 1 + 1:5
 paste(1:5, "A", sep="")


###################################################
### chunk number 7: matrixEx
###################################################
#line 168 "R_intro.Rnw"
x <- matrix(1:10, nrow=2)
dim(x)
x
as.vector(x)


###################################################
### chunk number 8: listenv
###################################################
#line 186 "R_intro.Rnw"
 lst = list(a=1:3, b = "ciao", c = sqrt)
 lst
 lst$c(81)


###################################################
### chunk number 9: env1
###################################################
#line 202 "R_intro.Rnw"
e1 = new.env()
e1[["a"]] <- 1:3
assign("b", "ciao", e1)
ls(e1)


###################################################
### chunk number 10: dataFrameEx
###################################################
#line 236 "R_intro.Rnw"
df <- data.frame(type=rep(c("case", "control"), c(2, 3)),
                 time=rexp(5))
df
df$time


###################################################
### chunk number 11: names1
###################################################
#line 259 "R_intro.Rnw"
x <- c(a=0, b=2)
x
names(x) <- c("Australia", "Brazil")
x


###################################################
### chunk number 12: names2
###################################################
#line 271 "R_intro.Rnw"
x <- matrix(c(4, 8, 5, 6, 4, 2, 1, 5, 7), nrow=3)
dimnames(x) <- list(
  year = c("2005", "2006", "2007"), 
  "mode of transport" = c("plane", "bus", "boat"))
x


###################################################
### chunk number 13: ExpressionSetSubsetting
###################################################
#line 312 "R_intro.Rnw"
library("Biobase")
data(sample.ExpressionSet)


###################################################
### chunk number 14: ExpressionSet1
###################################################
#line 317 "R_intro.Rnw"
class(sample.ExpressionSet)
dim(sample.ExpressionSet)
slotNames(sample.ExpressionSet)


###################################################
### chunk number 15: ExpressionSet2
###################################################
#line 325 "R_intro.Rnw"
sample.ExpressionSet


###################################################
### chunk number 16: posind
###################################################
#line 359 "R_intro.Rnw"
x <- 1:10
x[2]
x[1:3]


###################################################
### chunk number 17: posind2
###################################################
#line 369 "R_intro.Rnw"
 x[9:11]


###################################################
### chunk number 18: posind3
###################################################
#line 383 "R_intro.Rnw"
x[0:1]
x[c(0, 0, 0)]


###################################################
### chunk number 19: posind4
###################################################
#line 392 "R_intro.Rnw"
x[c(10, 2, NA)]


###################################################
### chunk number 20: posassign
###################################################
#line 407 "R_intro.Rnw"
x[2] <- 200
x[8:10] <- 10
x


###################################################
### chunk number 21: negsub
###################################################
#line 426 "R_intro.Rnw"
x[-(1:3)]


###################################################
### chunk number 22: logicalsub
###################################################
#line 449 "R_intro.Rnw"
x = 1:10
x > 5
x[x > 5]


###################################################
### chunk number 23: namedsub
###################################################
#line 472 "R_intro.Rnw"
x <- c(a=1, b=2, c=3)
x[c("c", "a", "foo")]


###################################################
### chunk number 24: arraysub
###################################################
#line 508 "R_intro.Rnw"
 x = matrix(1:9, ncol=3)
 x[ x > 6 ]
 x[ x > 6 ] = 0
 x


###################################################
### chunk number 25: 
###################################################
#line 536 "R_intro.Rnw"
 lst[1]


###################################################
### chunk number 26: 
###################################################
#line 542 "R_intro.Rnw"
 lst[[1]]


###################################################
### chunk number 27: 
###################################################
#line 561 "R_intro.Rnw"
 lst$a
 lst[["a"]]


###################################################
### chunk number 28: 
###################################################
#line 581 "R_intro.Rnw"
 e1$a
 e1[["b"]]


###################################################
### chunk number 29: 
###################################################
#line 597 "R_intro.Rnw"

 lst[[1]] = list(2,3)
 lst[[1]]

 e1$b = 1:10
 e1$b


###################################################
### chunk number 30: ExpressionSetSubsetting
###################################################
#line 612 "R_intro.Rnw"
sample.ExpressionSet[1:2, 2:5]


###################################################
### chunk number 31: plot1
###################################################
#line 689 "R_intro.Rnw"
x <- c(1,3,6,9,12)
y <- c(1,2,7,8,4)
plot(x,y)


###################################################
### chunk number 32: plot2
###################################################
#line 695 "R_intro.Rnw"
plot(x,y, main='Title here', col='red', pch=15)


###################################################
### chunk number 33: plot3
###################################################
#line 699 "R_intro.Rnw"
barplot(y)


###################################################
### chunk number 34: pasteExample
###################################################
#line 725 "R_intro.Rnw"
s <- c("apple", "banana", "lychee")
paste(s, "X", sep="_")
paste(s, collapse=", ")


###################################################
### chunk number 35: grepExample
###################################################
#line 733 "R_intro.Rnw"
library("ALL")
data(ALL)
class(ALL$mol.biol)
negIdx <- grep("NEG", ALL$mol.biol)
negIdx[1:10]


###################################################
### chunk number 36: apply1
###################################################
#line 774 "R_intro.Rnw"
a=matrix(runif(1e6), ncol=10)


###################################################
### chunk number 37: apply2
###################################################
#line 777 "R_intro.Rnw"
system.time({ 
  s1 = apply(a, 1, sum)
})
system.time({
  s2 = numeric(nrow(a))
  for(i in 1:nrow(a))
    s2[i] = sum(a[i,])
})


###################################################
### chunk number 38: sqfun
###################################################
#line 813 "R_intro.Rnw"

 square = function(x) x*x
 square(10)


###################################################
### chunk number 39: sf2
###################################################
#line 823 "R_intro.Rnw"
 square(1:4)


###################################################
### chunk number 40: callsumsq
###################################################
#line 836 "R_intro.Rnw"
 sumsq = function(x) sum(square(x))
 sumsq(1:10)


