Skip to contents

This function returns an object that implements the methods list(), save(), load(), remove() that list, store, load or remove, respectively .rds or .RData files. The object is associated to a folder that is given to this function.

Usage

createStorage(path, type = "rds")

Arguments

path

path to the folder in which to store the RDS files. If the folder does not exist it is attempted to be created.

type

one of "rds", "RData", specifying the format used to store R objects.

Value

list with "member functions" list(), save(),

load(), remove(), and variables path, type

Examples

# Create an empty test folder
path <- file.path(tempdir(), "test")
dir.create(path)

# Create a storage object pointing to a temporary test folder
storage <- kwb.utils::createStorage(path)
#> The directory "/var/folders/h1/8hndypj13nsbj5pn4xsnv1tm0000gn/T//Rtmp0pKi4m/test" already exists.

# At the beginning, the storage is empty
storage$list()
#> character(0)

# Store objects
apple <- 5
storage$save(apple, banana = list("Hello", "World"))

if (FALSE) {
# List the objects
storage$list()

# Retrieve an object
storage$load("banana")

# Remove objects
storage$remove("apple")
storage$remove("banana")

# The storage is empty again
storage$list()
}