Yet another assignment interface in order to allow to formulate x[index,...,add=TRUE]<-value in a way which works transparently, not only for ff, but also for ram objects: add(x, value, index, ...).

add(x, ...)
# S3 method for class 'ff'
add(x, value, ...)
# Default S3 method
add(x, value, ...)

Arguments

x

an ff or ram object

value

the amount to increment, possibly recylcled

...

further arguments – especially index information – passed to [<- or [<-.ff

Value

invisible()

Author

Jens Oehlschlägel

Note

Note that add.default changes the object in its parent frame and thus violates R's usual functional programming logic. Duplicated index positions should be avoided, because ff and ram objects behave differently:


  add.ff(x, 1, c(3,3))
  # will increment x at position 3 TWICE by 1, while
  add.default(x, 1, c(3,3))
  # will increment x at position 3 just ONCE by 1
  

See also

Examples

   message("incrementing parts of a vector")
#> incrementing parts of a vector
   x <- ff(0, length=12)
   y <- rep(0, 12)
   add(x, 1, 1:6)
   add(y, 1, 1:6)
   x
#> ff (open) double length=12 (12)
#>  [1]  [2]  [3]  [4]  [5]  [6]       [7]  [8]  [9] [10] [11] [12] 
#>    1    1    1    1    1    1    :    0    0    0    0    0    0 
   y
#>  [1] 1 1 1 1 1 1 0 0 0 0 0 0

   message("incrementing parts of a matrix")
#> incrementing parts of a matrix
   x <- ff(0, dim=3:4)
   y <- array(0, dim=3:4)
   add(x, 1, 1:2, 1:2)
   add(y, 1, 1:2, 1:2)
   x
#> ff (open) double length=12 (12) dim=c(3,4) dimorder=c(1,2)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    1    0    0
#> [2,]    1    1    0    0
#> [3,]    0    0    0    0
   y
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    1    0    0
#> [2,]    1    1    0    0
#> [3,]    0    0    0    0

   message("BEWARE that ff and ram methods differ in treatment of duplicated index positions")
#> BEWARE that ff and ram methods differ in treatment of duplicated index positions
   add(x, 1, c(3,3))
   add(y, 1, c(3,3))
   x
#> ff (open) double length=12 (12) dim=c(3,4) dimorder=c(1,2)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    1    0    0
#> [2,]    1    1    0    0
#> [3,]    2    0    0    0
   y
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    1    0    0
#> [2,]    1    1    0    0
#> [3,]    1    0    0    0

   rm(x); gc()
#>           used (Mb) gc trigger  (Mb) max used  (Mb)
#> Ncells 1014455 54.2    1994352 106.6  1994352 106.6
#> Vcells 1865875 14.3    8388608  64.0  3877600  29.6