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("Oarray-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('Oarray') Attaching package: 'Oarray' The following object(s) are masked from package:base : as.array > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Oarray" > > ### * Oarray > > flush(stderr()); flush(stdout()) > > ### Name: Oarray > ### Title: Arrays with arbitrary offsets > ### Aliases: Oarray as.Oarray as.array.default as.array as.array.Oarray > ### is.Oarray .handleTheOffset [.Oarray [<-.Oarray print.Oarray > ### Keywords: array > > ### ** Examples > > fred <- Oarray(1:24, 2:4, list(c("sad", "happy"), NULL, NULL), + offset=rep(7, 3)) > > tmp <- as.array(fred) > fred1 <- as.Oarray(tmp, offset=rep(7, 3)) > stopifnot(identical(fred, fred1)) > > print.default(fred) # print method provides numbers for , , 1 [,1] [,2] [,3] sad 1 3 5 happy 2 4 6 , , 2 [,1] [,2] [,3] sad 7 9 11 happy 8 10 12 , , 3 [,1] [,2] [,3] sad 13 15 17 happy 14 16 18 , , 4 [,1] [,2] [,3] sad 19 21 23 happy 20 22 24 attr(,"offset") [1] 7 7 7 attr(,"drop.negative") [1] TRUE attr(,"class") [1] "Oarray" > fred # non-named extents , , 7 [,7] [,8] [,9] sad 1 3 5 happy 2 4 6 , , 8 [,7] [,8] [,9] sad 7 9 11 happy 8 10 12 , , 9 [,7] [,8] [,9] sad 13 15 17 happy 14 16 18 , , 10 [,7] [,8] [,9] sad 19 21 23 happy 20 22 24 > > # examples of extraction > > fred[] # unclasses fred , , 1 [,1] [,2] [,3] sad 1 3 5 happy 2 4 6 , , 2 [,1] [,2] [,3] sad 7 9 11 happy 8 10 12 , , 3 [,1] [,2] [,3] sad 13 15 17 happy 14 16 18 , , 4 [,1] [,2] [,3] sad 19 21 23 happy 20 22 24 > fred["sad", 7, -9] [1] 1 7 19 > fred["sad", 7, -9, drop=FALSE] , , 1 [,1] sad 1 , , 2 [,1] sad 7 , , 3 [,1] sad 19 > fred[-8, , 7:8] [,1] [,2] [1,] 1 7 [2,] 3 9 [3,] 5 11 > > i <- 8:9; fred[, , i+1] , , 1 [,1] [,2] [,3] sad 13 15 17 happy 14 16 18 , , 2 [,1] [,2] [,3] sad 19 21 23 happy 20 22 24 > how.I.feel <- "happy"; fred[how.I.feel, , -(7:8)] [,1] [,2] [1,] 14 20 [2,] 16 22 [3,] 18 24 > > # examples of assignment > > fred["sad", 7, -9] <- NA > fred[, , i] <- 100 > fred[how.I.feel, , -(7:8)] <- Inf > > # now use negative offsets and suppress usual behaviour > > fred <- Oarray(24:1, 2:4, offset=c(-1, -2, 7), drop.negative=FALSE) > fred[] <- 1:24 > fred[-(1:0), , 7:8] , , 1 [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 , , 2 [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12 > fred[-(1:0), , 7:8] <- 100 > dimnames(fred) <- list(c("sad", "happy"), NULL, NULL) > fred["sad", -2, 10] <- NA > > > > ### *