Type: | Package |
Title: | Deferred List - A Read-Only List-Like Object with Deferred Access |
Version: | 0.2.0 |
Description: | 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. |
License: | LGPL-2.1 | LGPL-3 [expanded from: LGPL (≥ 2.1)] |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
Imports: | purrr, memoise, rlang, assertthat |
Suggests: | testthat (≥ 3.0.0), covr, knitr, rmarkdown |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
URL: | https://bbuchsbaum.github.io/deflist/ |
NeedsCompilation: | no |
Packaged: | 2023-04-26 13:35:29 UTC; bbuchsbaum |
Author: | Bradley Buchsbaum [aut, cre] |
Maintainer: | Bradley Buchsbaum <brad.buchsbaum@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-04-27 12:52:35 UTC |
Prevent assignment to elements in a deflist object
Description
Prevent assignment to elements in a deflist object
Usage
## S3 replacement method for class 'deflist'
x[i] <- value
Arguments
x |
A deflist object. |
i |
Indices or names of the elements to be assigned. |
value |
Values to be assigned to the elements. |
Value
this function throws an error be design, no return value
Subset a deflist object
Description
Subset a deflist object
Usage
## S3 method for class 'deflist'
x[i]
Arguments
x |
A deflist object. |
i |
Indices or names of the elements to be retrieved. |
Value
A list containing the elements at the specified indices or names in the deflist
object.
Prevent assignment to an element in a deflist object
Description
Prevent assignment to an element in a deflist object
Usage
## S3 replacement method for class 'deflist'
x[[i]] <- value
Arguments
x |
A deflist object. |
i |
Index or name of the element to be assigned. |
value |
Value to be assigned to the element. |
Value
this function throws an error be design, no return value
Retrieve an element from a deflist object
Description
Retrieve an element from a deflist object
Usage
## S3 method for class 'deflist'
x[[i]]
Arguments
x |
A deflist object. |
i |
Index or name of the element to be retrieved. |
Value
The element at the specified index or name in the deflist object.
Convert a deflist object to a list
Description
Convert a deflist object to a list
Usage
## S3 method for class 'deflist'
as.list(x, ...)
Arguments
x |
A deflist object. |
... |
Additional arguments passed to methods. |
Value
A list containing the elements of the deflist object.
Create a deferred list
Description
A read-only list that retrieves elements with a function call. The deferred list is useful for handling large datasets where elements are computed on-demand.
Usage
deflist(
fun,
len = 1,
names,
memoise = FALSE,
cache = c("memory", "file"),
cachedir = NULL
)
Arguments
fun |
A function that is used to retrieve elements. |
len |
Integer, the length of the list (default is 1). |
names |
Character vector, an optional set of names, one per element. |
memoise |
Logical, whether to memoise the function to speed up repeated element access (default is FALSE). |
cache |
Character, use an in-memory or filesystem cache if |
cachedir |
Character, the file path to the cache (default is NULL). |
Details
The deferred list is created using the provided function, length, names, and caching options. The list is read-only, and elements are retrieved using the provided function.
Value
An object of class "deflist" representing the deferred list.
Examples
# Create a deferred list of squares
square_fun <- function(i) i^2
square_deflist <- deflist(square_fun, len = 5)
print(square_deflist)
cat("First element of the list:", square_deflist[[1]], "\n")
Retrieve the length of a deflist object
Description
Retrieve the length of a deflist object
Usage
## S3 method for class 'deflist'
length(x)
Arguments
x |
A deflist object. |
Value
The length of the deflist object.
Examples
square_fun <- function(i) i^2
square_deflist <- deflist(square_fun, len = 5)
stopifnot(length(square_deflist) == 5)