Assigning dim to an ff_vector changes it to an ff_array. Beyond that dimorder can be assigned to change from column-major order to row-major order or generalizations for higher order ff_array.

# S3 method for class 'ff'
dim(x)
  # S3 method for class 'ffdf'
dim(x)
  # S3 method for class 'ff'
dim(x) <- value
  # S3 method for class 'ffdf'
dim(x) <- value
   dimorder(x, ...)
dimorder(x, ...) <- value
  # Default S3 method
dimorder(x, ...)
  # S3 method for class 'ff_array'
dimorder(x, ...)
  # S3 method for class 'ffdf'
dimorder(x, ...)
  # S3 method for class 'ff_array'
dimorder(x, ...) <- value
  # S3 method for class 'ffdf'
dimorder(x, ...) <- value

Arguments

x

a ff object

value

an appropriate integer vector

...

further arguments (not used)

Details

dim and dimorder are virtual attributes. Thus two copies of an R ff object can point to the same file but interpret it differently. dim has the usual meaning, dimorder defines the dimension order of storage, i.e. c(1,2) corresponds to R's standard column-major order, c(1,2) corresponds to row-major order, and for higher dimensional arrays dimorder can also be used. Standard dimorder is seq_along(dim(x)).
For ffdf dim returns the number of rows and virtual columns. With dim<-.ffdf only the number of rows can be changed. For convenience you can assign NA to the number of columns.
For ffdf the dimorder returns non-standard dimorder if any of its columns contains a ff object with non-standard dimorder (see dimorderStandard) An even higher level of virtualization is available using virtual windows, see vw.

Note

x[] returns a matrix like x[,] and thus respects dimorder, while x[i:j] returns a vector and simply returns elements in the stored order. Check the corresponding example twice, in order to make sure you understand that for non-standard dimorder x[seq_along(x)] is not the same as as.vector(x[]).

Value

names returns a character vector (or NULL)

Author

Jens Oehlschlägel

Examples

  x <- ff(1:12, dim=c(3,4), dimorder=c(2:1))
  y <- x
  dim(y) <- c(4,3)
  dimorder(y) <- c(1:2)
  x
#> ff (open) integer length=12 (12) dim=c(3,4) dimorder=c(2,1)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12
  y
#> ff (open) integer length=12 (12) dim=c(4,3) dimorder=c(1,2)
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    4    5    6
#> [3,]    7    8    9
#> [4,]   10   11   12
  x[]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12
  y[]
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    4    5    6
#> [3,]    7    8    9
#> [4,]   10   11   12
  x[,bydim=c(2,1)]
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    4    5    6
#> [3,]    7    8    9
#> [4,]   10   11   12
  y[,bydim=c(2,1)]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12

  message("NOTE that x[] like x[,] returns a matrix (respects dimorder),")
#> NOTE that x[] like x[,] returns a matrix (respects dimorder),
  message("while x[1:12] returns a vector IN STORAGE ORDER")
#> while x[1:12] returns a vector IN STORAGE ORDER
  message("check the following examples twice to make sure you understand this")
#> check the following examples twice to make sure you understand this
  x[,]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12
  x[]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    4    7   10
#> [2,]    2    5    8   11
#> [3,]    3    6    9   12
  as.vector(x[])
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12
  x[1:12]
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12
  rm(x,y); gc()
#>           used (Mb) gc trigger  (Mb) max used  (Mb)
#> Ncells 1137259 60.8    1994352 106.6  1994352 106.6
#> Vcells 2113055 16.2    8388608  64.0  3981144  30.4

#> some regression test with regard to different dimorders
  if (FALSE) { # \dontrun{
    message("some performance comparison between different dimorders")
    n <- 100
    m <- 100000
    a <- ff(1L,dim=c(n,m))
    b <- ff(1L,dim=c(n,m), dimorder=2:1)
    system.time(lapply(1:n, function(i)sum(a[i,])))
    system.time(lapply(1:n, function(i)sum(b[i,])))
    system.time(lapply(1:n, function(i){i<-(i-1)*(m/n)+1; sum(a[,i:(i+m/n-1)])}))
    system.time(lapply(1:n, function(i){i<-(i-1)*(m/n)+1; sum(b[,i:(i+m/n-1)])}))
    rm(a,b); gc()
  } # }