R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("sfsmisc-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('sfsmisc') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "AsciiToInt" > > ### * AsciiToInt > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: AsciiToInt > ### Title: Character to and from Integer Codes Conversion > ### Aliases: AsciiToInt ichar chars8bit strcodes > ### Keywords: manip > > ### ** Examples > > chars8bit(65:70)#-> "A" "B" .. "F" [1] "A" "B" "C" "D" "E" "F" > stopifnot(identical(LETTERS, chars8bit(65:90)), + identical(AsciiToInt(LETTERS), 65:90)) > ## Not run: > ##D ## may only work in ISO-latin1 locale (not in UTF-8): > ##D strcodes(c(a= "ABC", ch="1234", place = "Zürich")) > ##D ## gives > ##D $a > ##D [1] 65 66 67 > ##D > ##D $ch > ##D [1] 49 50 51 52 > ##D > ##D $place > ##D [1] 90 252 114 105 99 104 > ## End(Not run) > > > > cleanEx(); ..nameEx <- "D1D2" > > ### * D1D2 > > flush(stderr()); flush(stdout()) > > ### Name: D1D2 > ### Title: Numerical Derivatives of (x,y) Data via Smoothing Splines > ### Aliases: D1D2 > ### Keywords: smooth > > ### ** Examples > > set.seed(8840) > x <- runif(100, 0,10) > y <- sin(x) + rnorm(100)/4 > > op <- par(mfrow = c(2,1)) > plot(x,y) > lines(ss <- smooth.spline(x,y), col = 4) > str(ss[c("df", "spar")]) List of 2 $ df : num 10.3 $ spar: num 0.716 > if(is.R()) plot(cos, 0, 10, ylim = c(-1.5,1.5), lwd=2) else { # Splus + xx <- seq(0,10, len=201); plot(xx, cos(xx), type = 'l', ylim = c(-1.5,1.5)) + } > title(expression("Estimating f'() : " * frac(d,dx) * sin(x) == cos(x))) > offs <- c(-0.1, 0, 0.1, 0.2, 0.3) > i <- 1 > for(off in offs) { + d12 <- D1D2(x,y, spar.offset = off) + lines(d12$x, d12$D1, col = i <- i+1) + } > legend(2,1.6, c("true cos()",paste("sp.off. = ", format(offs))), lwd=1, + col = 1:(1+length(offs)), cex = 0.8, bg = NA) > par(op) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "D2ss" > > ### * D2ss > > flush(stderr()); flush(stdout()) > > ### Name: D2ss > ### Title: Numerical Derivatives of (x,y) Data (via Smoothing Splines) > ### Aliases: D2ss D1ss D1tr > ### Keywords: smooth > > ### ** Examples > > > ## First Derivative --- spar.off = 0 ok "asymptotically" (?) > set.seed(330) > mult.fig(12) > for(i in 1:12) { + x <- runif(500, 0,10); y <- sin(x) + rnorm(500)/4 + f1 <- D1ss(x=x,y=y, spar.off=0.0) + plot(x,f1, ylim = range(c(-1,1,f1))) + curve(cos(x), col=3, add= TRUE) + } > > set.seed(8840) > x <- runif(100, 0,10) > y <- sin(x) + rnorm(100)/4 > > op <- par(mfrow = c(2,1)) > plot(x,y) > lines(ss <- smooth.spline(x,y), col = 4) > str(ss[c("df", "spar")]) List of 2 $ df : num 10.3 $ spar: num 0.716 > xx <- seq(0,10, len=201) > plot(xx, -sin(xx), type = 'l', ylim = c(-1.5,1.5)) > title(expression("Estimating f''() : " * frac(d^2,dx^2) * sin(x) == -sin(x))) > offs <- c(0.05, 0.1, 0.1348, 0.2) > i <- 1 > for(off in offs) { + d12 <- D2ss(x,y, spar.offset = off) + lines(d12, col = i <- i+1) + } > legend(2,1.6, c("true : -sin(x)",paste("sp.off. = ", format(offs))), lwd=1, + col = 1:(1+length(offs)), cex = 0.8, bg = NA) > par(op) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "KSd" > > ### * KSd > > flush(stderr()); flush(stdout()) > > ### Name: KSd > ### Title: Approximate Critical Values for Kolmogorov-Smirnov's D > ### Aliases: KSd > ### Keywords: distribution > > ### ** Examples > > KSd(90) [1] 0.1411873 > KSd(1:9)# now works [1] 0.97500 0.84189 0.70760 0.62394 0.56328 0.51926 0.48342 0.45427 0.43001 > > op <- par(mfrow=c(2,1)) > plot(KSd, 10, 150)# nice > abline(v = c(75,85), col = "gray") > plot(KSd, 79, 81, n = 1001)# *very* tiny discontinuity at 80 > par(op) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "QUnif" > > ### * QUnif > > flush(stderr()); flush(stdout()) > > ### Name: QUnif > ### Title: Quasi Randum Numbers via Halton Sequences > ### Aliases: QUnif sHalton > ### Keywords: math multivariate datagen > > ### ** Examples > > 32*sHalton(20, base=2) [1] 16 8 24 4 20 12 28 2 18 10 26 6 22 14 30 1 17 9 25 5 > > stopifnot(sHalton(20, base=3, leap=2) == + sHalton(20, base=3)[1+2*(0:9)]) > ## ------- a 2D Visualization ------- > > Uplot <- function(xy, axes=FALSE, xlab="", ylab="", ...) { + plot(xy, xaxs="i", yaxs="i", xlim=0:1, ylim=0:1, xpd = FALSE, + axes=axes, xlab=xlab, ylab=ylab, ...) + box(lty=2, col="gray40") + } > > do4 <- function(n, ...) { + op <- mult.fig(4, main=paste("n =", n,": Quasi vs. (Pseudo) Random"), + marP=c(-2,-2,-1,0))$old.par + on.exit(par(op)) + for(i in 1:2) { + Uplot(QUnif(n, p=2), main="QUnif", ...) + Uplot(cbind(runif(n), runif(n)), main="runif", ...) + } + } > do4(100) > do4(500) > do4(1000, cex = 0.8, col="slateblue") > do4(10000, pch= ".", col="slateblue") > do4(40000, pch= ".", col="slateblue") > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "Sys.cpuinfo" > > ### * Sys.cpuinfo > > flush(stderr()); flush(stdout()) > > ### Name: Sys.cpuinfo > ### Title: Provide Information about the CPU > ### Aliases: Sys.cpuinfo Sys.MIPS > ### Keywords: utilities > > ### ** Examples > > cbind(Sys.cpuinfo()) Warning: cannot open file '/proc/cpuinfo' Error in file(con, "r") : unable to open connection Execution halted