Learn R Programming

hashmap (version 0.2.2)

save_hashmap: Save Hashmaps

Description

save_hashmap writes a Hashmap's data to the specified file, which can be passed to load_hashmap at a later point in time to recreate the object.

Usage

save_hashmap(x, file, overwrite = TRUE, compress = FALSE)

Arguments

x

an object created by a call to hashmap.

file

a filename where the object's data will be saved.

overwrite

if TRUE (default) and file exists, it will be overwritten. If FALSE and file exists, an error is thrown.

compress

a logical value or the type of file compression to use; defaults to FALSE for better performance. See ?saveRDS for details.

Value

Nothing on success; an error on failure.

Details

Saving is done by calling base::saveRDS on the object's data.frame representation, x$data.frame(). Attempting to save an empty Hashmap results in an error.

See Also

load_hashmap, saveRDS

Examples

Run this code
# NOT RUN {
H <- hashmap(sample(letters[1:10]), sample(1:10))
tf <- tempfile()

save_hashmap(H, tf)

inherits(
    try(save_hashmap(H, tf, FALSE), silent = TRUE),
    "try-error"
)

H$insert("zzzzz", 123L)
save_hashmap(H, tf)

load_hashmap(tf)
# }

Run the code above in your browser using DataLab