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("session-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('session') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "session" > > ### * session > > flush(stderr()); flush(stdout()) > > ### Name: save.session > ### Title: Save and restore session information, including loaded packages > ### and attached data objects. > ### Aliases: save.session restore.session > ### Keywords: data programming > > ### ** Examples > > > ls(all=TRUE) # show all data objects [1] "..nameEx" ".Random.seed" > search() # list search path [1] ".GlobalEnv" "package:session" "CheckExEnv" [4] "package:methods" "package:stats" "package:graphics" [7] "package:grDevices" "package:utils" "package:datasets" [10] "Autoloads" "package:base" > > # save the current R session to the file "RSession.Rda" > save.session("RSession.Rda") Warning in save.session("RSession.Rda") : Open graphics devices will not be saved or restored. Saving search path.. Saving list of loaded packages.. Saving all data... Done. > > ## Not run: > ##D # exit R without saving data > ##D q("no") > ##D > ##D # restart R > ##D R > ##D > ## End(Not run) > > # load a saved R session from "RSession.Rda" > restore.session("RSession.Rda") Loading all data... Loading packages... Restoring search path... Done. > > ls(all=TRUE) # show all data objects [1] "..nameEx" ".Random.seed" > search() # list search path [1] ".GlobalEnv" "package:session" "CheckExEnv" [4] "package:methods" "package:stats" "package:graphics" [7] "package:grDevices" "package:utils" "package:datasets" [10] "Autoloads" "package:base" > > > > > cleanEx(); ..nameEx <- "texteval" > > ### * texteval > > flush(stderr()); flush(stdout()) > > ### Name: texteval > ### Title: Evaluate string(s) containing R commands and return the text > ### transcript or printed results > ### Aliases: capture texteval printed > ### Keywords: data programming > > ### ** Examples > > > # define a script string > script <- "x <- rnorm(100)\ny <- x + rnorm(100,0.25)\nsummary(lm(y~x))" > > # evaluate the script string, returning a transcript. > result <- texteval(script, "\n") > cat(result) > x <- rnorm(100) > y <- x + rnorm(100, 0.25) > summary(lm(y ~ x)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -1.8768 -0.6138 -0.1395 0.5394 2.3462 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.21231 0.09699 2.189 0.031 * x 0.99894 0.10773 9.273 4.58e-15 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.9628 on 98 degrees of freedom Multiple R-Squared: 0.4674, Adjusted R-squared: 0.4619 F-statistic: 85.99 on 1 and 98 DF, p-value: 4.583e-15 > > # evaluate the script string, returning the printed output. > result <- printed(script, "\n") > cat(result) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -2.74179 -0.56139 -0.01749 0.67973 1.84843 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.29845 0.09910 3.012 0.00331 ** x 1.10622 0.09626 11.492 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.9906 on 98 degrees of freedom Multiple R-Squared: 0.574, Adjusted R-squared: 0.5697 F-statistic: 132.1 on 1 and 98 DF, p-value: < 2.2e-16 > > > > > ### *