MyNixOS website logo
Description

Deferred List - A Read-Only List-Like Object with Deferred Access.

Implements the 'deflist' class, a read-only list-like object that accesses its elements via a function. The 'deflist' class can be used to model deferred access to data or computations by routing indexed list access to a function. This approach is particularly useful when sequential list-like access to data is required but holding all the data in memory at once is not feasible. The package also provides utilities for memoisation and caching to optimize access to frequently requested elements.

deflist

R-CMD-check

The goal of deflist is to provide a list-like object for which element access is routed through a user-supplied function. This can be used, for example, when list-like syntax is required but one cannot afford to hold all elements in memory at once.

Installation

You can install the released version of deflist from CRAN with:

install.packages("deflist")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("bbuchsbaum/deflist")

Examples


library(deflist)

dl <- deflist(function(i) i, len=10)
print(dl[[1]])
#> [1] 1

dl2 <- deflist(function(i) { Sys.sleep(5); i*2  }, len=10)

for (i in 1:10) {
  print(dl2[[i]])
}
#> [1] 2
#> [1] 4
#> [1] 6
#> [1] 8
#> [1] 10
#> [1] 12
#> [1] 14
#> [1] 16
#> [1] 18
#> [1] 20

The value at an index may change across calls, for example:

dl3 <- deflist(function(i) { rnorm(1) }, len=10)
print(dl3[[1]])
#> [1] 0.3200255
print(dl3[[1]])
#> [1] 0.3937322

Memoisation can be enabled so that values at a given index are cached:

dl4 <- deflist(function(i) { rnorm(1)  }, len=10, memoise=TRUE)
print(dl4[[1]])
#> [1] 0.1447534
print(dl4[[1]])
#> [1] 0.1447534

In addition, memoisation can be set to store cached values to the file system:

dl5 <- deflist(function(i) { rnorm(1000)  }, len=10, memoise=TRUE, cache="file", cachedir = tempdir())
print(dl5[[1]][1:10])
#>  [1]  0.23399448  0.93722807 -0.34288042  0.36736236  0.87024915 -0.86566821
#>  [7]  1.57174277 -0.38036486 -0.04497923 -0.34889371
print(dl5[[1]][1:10])
#>  [1]  0.23399448  0.93722807 -0.34288042  0.36736236  0.87024915 -0.86566821
#>  [7]  1.57174277 -0.38036486 -0.04497923 -0.34889371
Metadata

Version

0.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows