Oarray                package:Oarray                R Documentation

_A_r_r_a_y_s _w_i_t_h _a_r_b_i_t_r_a_r_y _o_f_f_s_e_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     The traditional R array has extents which are indexed with
     integers that start at 1.  This is generalized to arbitrary
     offsets, where extent `i' is indexed with integers that start at
     `offset[i]', which must be no less than zero to accomodate the R
     convention of dropping components with negative indices.  In order
     to use negative offsets, the flag `drop.negative' can be set
     `FALSE'.

_U_s_a_g_e:

     Oarray(data=NA, dim=length(data), dimnames=NULL, offset=NA,
       drop.negative=TRUE)
     as.Oarray(x, offset=NA, drop.negative=TRUE)
     as.array.Oarray(x)
     [.Oarray(x, ...)
     [<-.Oarray(x, ..., value)
     print.Oarray(x, ...)

_A_r_g_u_m_e_n_t_s:

data, dim, dimnames: As in the function `array'

  offset: Vector of first index values for each extent (defaults to 1s)

drop.negative: Should negative subscripts indicate exclusion?

       x: An array, possibly of class `Oarray'

   value: Vector to be substituted into `x'

_V_a_l_u_e:

     Typically and array with or without a `Oarray' class attribute. 
     Extracting from an `Oarray' object unclasses the result which is
     then a simple array, but assigning into an `Oarray' object leaves
     the result as an `Oarray' object.

     The print method provides more informative extent labelling in the
     case where dimnames are not provided.

_S_i_d_e _e_f_f_e_c_t_s:

     The function `as.array' from package:base is redefined to provide
     an `as.array.Oarray' method.

_N_o_t_e:

     The use of `drop=FALSE' will only work in `[.Oarray' where it is
     provided as the final argument inside the square brackets.

     The function `.handleTheOffset' is not for general use.

_A_u_t_h_o_r(_s):

     Jonathan Rougier, J.C.Rougier@durham.ac.uk

_S_e_e _A_l_s_o:

     `array'

_E_x_a_m_p_l_e_s:

     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(is.Oarray(fred1), all.equal(fred, fred1))

     print.default(fred)  # print method provides numbers for
     fred                 # non-named extents

     # examples of extraction

     fred[] # unclasses fred
     fred["sad", 7, -9]
     fred["sad", 7, -9, drop=FALSE]
     fred[-8, , 7:8]

     i <- 8:9; fred[, , i+1]
     how.I.feel <- "happy"; fred[how.I.feel, , -(7:8)]

     # 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]
     fred[-(1:0), , 7:8] <- 100
     dimnames(fred) <- list(c("sad", "happy"), NULL, NULL)
     fred["sad", -2, 10] <- NA

