### R code from vignette source '02software.Rnw' ## Copyright (C) Adrian Baddeley, Ege Rubak and Rolf Turner ################################################### ### code chunk number 1: 02software.Rnw:9-10 ################################################### source("R/startup.R") ################################################### ### code chunk number 2: 02software.Rnw:184-185 (eval = FALSE) ################################################### ## ################################################### ### code chunk number 3: 02software.Rnw:189-193 (eval = FALSE) ################################################### ## 1+1 ## 3 * (10 + 5) ## 2:5 ## sqrt(2) ################################################### ### code chunk number 4: 02software.Rnw:201-205 ################################################### 1+1 3 * (10 + 5) 2:5 sqrt(2) ################################################### ### code chunk number 5: 02software.Rnw:209-210 ################################################### opa <- options(width=78) ################################################### ### code chunk number 6: 02software.Rnw:212-213 ################################################### (1:30)^2 ################################################### ### code chunk number 7: 02software.Rnw:215-216 ################################################### options(opa) ################################################### ### code chunk number 8: 02software.Rnw:220-222 ################################################### x <- 17 x ################################################### ### code chunk number 9: 02software.Rnw:231-232 ################################################### options(continue="+") ################################################### ### code chunk number 10: 02software.Rnw:234-237 ################################################### folderol <- 1.2 sin(folderol * folderol * folderol * folderol * folderol * folderol * folderol * folderol * folderol) ################################################### ### code chunk number 11: 02software.Rnw:239-240 ################################################### options(continue=" ") ################################################### ### code chunk number 12: 02software.Rnw:327-331 ################################################### x <- c(3.2, 1.5, 3.6, 9.2, 2.4) x y <- 1:5 y ################################################### ### code chunk number 13: 02software.Rnw:339-341 ################################################### x + 5 x/y ################################################### ### code chunk number 14: 02software.Rnw:345-347 ################################################### month.name x > 3 ################################################### ### code chunk number 15: 02software.Rnw:351-353 ################################################### x[2] month.name[8] ################################################### ### code chunk number 16: 02software.Rnw:394-396 ################################################### b <- list(c("Tuesday", "Friday"), 3:7, c(FALSE,TRUE)) b ################################################### ### code chunk number 17: 02software.Rnw:412-414 ################################################### b[2] b[[2]] ################################################### ### code chunk number 18: 02software.Rnw:423-426 ################################################### b <- list(Day="Tuesday", Number=3:7, Answers=c(FALSE,TRUE)) names(b) b ################################################### ### code chunk number 19: 02software.Rnw:429-430 ################################################### names(b) <- c("Day", "Number", "Answers") ################################################### ### code chunk number 20: 02software.Rnw:434-436 ################################################### b[c("Day", "Answers")] b[["Day"]] ################################################### ### code chunk number 21: 02software.Rnw:440-441 ################################################### b$Day ################################################### ### code chunk number 22: 02software.Rnw:459-462 ################################################### m <- matrix(1:12, nrow=3, ncol=4) m m[2,3] ################################################### ### code chunk number 23: 02software.Rnw:471-473 ################################################### m[2,] m[,3] ################################################### ### code chunk number 24: 02software.Rnw:477-478 ################################################### m[5] ################################################### ### code chunk number 25: 02software.Rnw:481-482 ################################################### matrix(1:12, nrow=3, ncol=4, byrow=TRUE) ################################################### ### code chunk number 26: 02software.Rnw:487-490 ################################################### d <- data.frame(i=7:10, month=month.name[7:10], has.r=((1:4) > 2)) d ################################################### ### code chunk number 27: 02software.Rnw:498-500 ################################################### colnames(d) <- c("month", "name", "has.r") d ################################################### ### code chunk number 28: 02software.Rnw:503-505 ################################################### d[2,3] d[,3] ################################################### ### code chunk number 29: 02software.Rnw:511-514 ################################################### d[[3]] d[c("month","name")] d$month ################################################### ### code chunk number 30: 02software.Rnw:553-556 (eval = FALSE) ################################################### ## plot(sunspots) ## summary(sunspots) ## X <- sunspots ################################################### ### code chunk number 31: 02software.Rnw:561-562 ################################################### class(sunspots) ################################################### ### code chunk number 32: 02software.Rnw:597-598 (eval = FALSE) ################################################### ## methods(plot) ################################################### ### code chunk number 33: 02software.Rnw:602-603 (eval = FALSE) ################################################### ## methods(class="ts") ################################################### ### code chunk number 34: 02software.Rnw:623-625 ################################################### 1+1 sin(pi/3) ################################################### ### code chunk number 35: 02software.Rnw:629-632 ################################################### fun <- function(){invisible(42)} fun() ################################################### ### code chunk number 36: 02software.Rnw:636-638 ################################################### x <- fun() x ################################################### ### code chunk number 37: 02software.Rnw:641-642 ################################################### (fun()) ################################################### ### code chunk number 38: 02software.Rnw:690-695 ################################################### col <- c("red", "green", "red", "blue", "blue", "green", "red") col f <- factor(col) f ################################################### ### code chunk number 39: 02software.Rnw:705-707 ################################################### is.factor(col) is.factor(f) ################################################### ### code chunk number 40: 02software.Rnw:714-715 ################################################### factor(col, levels=c("red", "green", "blue"), labels=c("r","g","b")) ################################################### ### code chunk number 41: 02software.Rnw:732-734 ################################################### x <- c(1,7,4,10,2,14,15,4,9) cut(x, c(0,5,10,15)) ################################################### ### code chunk number 42: 02software.Rnw:752-753 ################################################### as.integer(f) ################################################### ### code chunk number 43: 02software.Rnw:756-757 ################################################### levels(f) ################################################### ### code chunk number 44: 02software.Rnw:776-783 ################################################### x <- factor(c("1.02","2.03","2.03", "1.02","3.04","1.02", "2.03","1.02","3.04","2.03")) x as.numeric(x) as.numeric(as.character(x)) as.numeric(levels(x))[x] ################################################### ### code chunk number 45: 02software.Rnw:819-822 ################################################### a <- (y ~ x + z) a class(a) ################################################### ### code chunk number 46: PromptOff.Rnw:1-2 ################################################### options(prompt=" ") ################################################### ### code chunk number 47: 02software.Rnw:835-837 (eval = FALSE) ################################################### ## plot(y ~ x) ## lm(y ~ x) ################################################### ### code chunk number 48: PromptOn.Rnw:1-2 ################################################### options(prompt="> ") ################################################### ### code chunk number 49: 02software.Rnw:865-866 (eval = FALSE) ################################################### ## plot(stack.loss ~ Water.Temp, data=stackloss) ################################################### ### code chunk number 50: 02software.Rnw:873-874 (eval = FALSE) ################################################### ## plot(weight ~ feed, data=chickwts) ################################################### ### code chunk number 51: fv2.Rnw:3-5 ################################################### newplot(12, 0.95) setmargins(0.5+c(3,3,0,1)) ################################################### ### code chunk number 52: 02software.Rnw:884-886 ################################################### setmargins(3,4,0.2,1) setpar(font.lab=1) ################################################### ### code chunk number 53: 02software.Rnw:890-894 ################################################### par(mfrow=c(1,2), pty="s") plot(stack.loss ~ Water.Temp, data=stackloss) plot(weight ~ feed, data=chickwts) par(mfrow=c(1,1)) ################################################### ### code chunk number 54: 02software.Rnw:905-906 ################################################### resetpar() ################################################### ### code chunk number 55: 02software.Rnw:919-920 (eval = FALSE) ################################################### ## plot(stack.loss ~ Water.Temp + Air.Flow, data=stackloss) ################################################### ### code chunk number 56: 02software.Rnw:931-934 (eval = FALSE) ################################################### ## library(scatterplot3d) ## with(stackloss, ## scatterplot3d(stack.loss ~ Water.Temp + Air.Flow)) ################################################### ### code chunk number 57: 02software.Rnw:941-944 ################################################### fut <- lm(stack.loss ~ Water.Temp, data=stackloss) co <- coef(fut) co <- round(co, 3) ################################################### ### code chunk number 58: 02software.Rnw:953-954 (eval = FALSE) ################################################### ## lm(stack.loss ~ Water.Temp, data=stackloss) ################################################### ### code chunk number 59: 02software.Rnw:963-964 ################################################### fut ################################################### ### code chunk number 60: 02software.Rnw:1001-1002 (eval = FALSE) ################################################### ## lm(stack.loss ~ Water.Temp + Air.Flow, data=stackloss) ################################################### ### code chunk number 61: 02software.Rnw:1012-1013 (eval = FALSE) ################################################### ## lm(stack.loss ~ Water.Temp - 1, data=stackloss) ################################################### ### code chunk number 62: 02software.Rnw:1023-1024 ################################################### lm(weight ~ feed - 1, data=chickwts) ################################################### ### code chunk number 63: 02software.Rnw:1156-1159 (eval = FALSE) ################################################### ## library(maptools) ## data(SplashDams) ## SplashDams[1:3,] ################################################### ### code chunk number 64: 02software.Rnw:1528-1530 ################################################### spatstat.options(terse=3) oldopt <- options(digits=3) ################################################### ### code chunk number 65: 02software.Rnw:1539-1540 ################################################### swedishpines ################################################### ### code chunk number 66: 02software.Rnw:1546-1547 ################################################### swp <- rescale(swedishpines) ################################################### ### code chunk number 67: 02software.Rnw:1550-1551 (eval = FALSE) ################################################### ## plot(swp) ################################################### ### code chunk number 68: 02software.Rnw:1556-1557 ################################################### DD <- density(swp) ################################################### ### code chunk number 69: 02software.Rnw:1559-1560 (eval = FALSE) ################################################### ## plot(DD) ################################################### ### code chunk number 70: 02software.Rnw:1566-1567 ################################################### KK <- Kest(swp) ################################################### ### code chunk number 71: 02software.Rnw:1569-1570 (eval = FALSE) ################################################### ## plot(KK) ################################################### ### code chunk number 72: 02software.Rnw:1577-1579 ################################################### newplot(12, 0.58) setmargins(1.5,0,0,0) ################################################### ### code chunk number 73: 02software.Rnw:1581-1585 ################################################### swp <- rescale(swedishpines) plot(solist(swp, density(swp)), equal.scales=TRUE, valign=TRUE, main="", main.panel="", mar.panel=0, hsep=1, ribside="bottom") ################################################### ### code chunk number 74: fv.Rnw:3-5 ################################################### newplot(6, 0.5) setmargins(0.5+c(3,3,1,0)) ################################################### ### code chunk number 75: 02software.Rnw:1589-1590 ################################################### setmargins(c(3.5,3.5,0,0)) ################################################### ### code chunk number 76: 02software.Rnw:1592-1593 ################################################### plot(Kest(swp), main="", xlim=c(0,1.5), legend=FALSE) ################################################### ### code chunk number 77: 02software.Rnw:1608-1609 ################################################### fitS <- ppm(swp ~ polynom(x,y,2), Strauss(0.9)) ################################################### ### code chunk number 78: 02software.Rnw:1615-1616 ################################################### fitS ################################################### ### code chunk number 79: 02software.Rnw:1620-1622 ################################################### fitP <- ppm(swp ~ polynom(x,y,2), Poisson()) anova(fitP, fitS, test="LR") ################################################### ### code chunk number 80: 02software.Rnw:1641-1642 ################################################### class(swedishpines) ################################################### ### code chunk number 81: 02software.Rnw:1658-1660 ################################################### DD <- density(swp) class(DD) ################################################### ### code chunk number 82: 02software.Rnw:1672-1674 ################################################### KK <- Kest(swp) class(KK) ################################################### ### code chunk number 83: 02software.Rnw:1680-1682 ################################################### fitS <- ppm(swp ~ polynom(x,y,2), Strauss(0.9)) class(fitS) ################################################### ### code chunk number 84: 02software.Rnw:1694-1696 ################################################### spatstat.options(terse=0) options(oldopt) ################################################### ### code chunk number 85: 02software.Rnw:1716-1717 (eval = FALSE) ################################################### ## help.search("systematic", package="spatstat") ################################################### ### code chunk number 86: 02software.Rnw:1807-1808 ################################################### zeromargins() ################################################### ### code chunk number 87: 02software.Rnw:1812-1816 ################################################### plot(solist(swedishpines, amacrine, longleaf), main="", main.panel="", equal.scales=FALSE, legend=FALSE, panel.args=function(i) if(i == 2) list(chars=c(1,16)) else list(), mar.panel=0.2, hsep=1) ################################################### ### code chunk number 88: 02software.Rnw:1851-1853 ################################################### zeromargins() setmargins(0,0.1,0,0.2) ################################################### ### code chunk number 89: 02software.Rnw:1857-1862 ################################################### W <- as.owin(humberside) plot(solist(as.rectangle(W), W, as.mask(W, dimyx=32)), equal.scales=TRUE, panel.args=function(i) if(i == 3) list(box=FALSE) else list(), main="", main.panel="", mar.panel=0, hsep=1) ################################################### ### code chunk number 90: 02software.Rnw:1873-1874 ################################################### Z <- rotate(Smooth(distmap(copper$Lines)), pi/2) ################################################### ### code chunk number 91: CopperR.Rnw:3-5 ################################################### newplot(12, 0.8) setmargins(0,0,0,1) ################################################### ### code chunk number 92: 02software.Rnw:1892-1893 ################################################### plot(Z, main="") ################################################### ### code chunk number 93: 02software.Rnw:1916-1918 ################################################### L <- psp(runif(20),runif(20),runif(20),runif(20),window=owin()) D <- dirichlet(runifpoint(42)) ################################################### ### code chunk number 94: Unit2.Rnw:3-5 ################################################### newplot(12.5, 0.9) setmargins(0) ################################################### ### code chunk number 95: 02software.Rnw:1922-1923 ################################################### zeromargins() ################################################### ### code chunk number 96: 02software.Rnw:1927-1930 ################################################### plot(solist(L, D), main="", main.panel="", equal.scales=TRUE, mar.panel=0.1, hsep=1)