plot.leaf <- function(n = 50000, col = "green", cex = 2) { x <- c(0.5, 0.5) plot(x[1], x[2], xlim = c(-3, 3), ylim = c(0, 10), type = "n", xlab = "", ylab = "") p <- c(0.85, 0.92, 0.99, 1) A <- rbind(c(0.85, 0.04), c(-0.04, 0.85), c(0.2, -0.26), c(0.23, 0.22), c(-0.15, 0.28), c(0.26, 0.24), c(0, 0), c(0, 0.16)) B <- cbind(c(0, 1.6), c(0, 1.6), c(0, 0.44), c(0, 0)) for (i in 1:n) { ran <- runif(1) ind <- rank(c(p, ran), ties.method = "min")[5] x <- A[(2 * ind - 1):(2 * ind), ] %*% x + B[, ind] points(x[1], x[2], pch = ".", cex = cex, col = col) } } ## plot leaf par(mar = c(0, 0, 0, 0) + 0.1) plot.leaf(cex = 1.6) box()
1 + 1
#: [1] 2
sqrt(-1) # warning
#: Warning: NaNs produced
#: [1] NaN
message("knitr says hello to HTML!") # message
1 + "a" # error
#: Error: non-numeric argument to binary operator
Let's ask R what is the value of π? Of course it is 3.1416
.