createStorage: Create Storage Object to Save/Load .rds or .RData files

View source: R/createStorage.R

createStorageR Documentation

Create Storage Object to Save/Load .rds or .RData files

Description

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)

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

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

## Not run: 
# 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()

## End(Not run)

KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.