R: Save Hashmaps

save_hashmap {hashmap} | R Documentation

## 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.

### 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.

### Value

Nothing on success; an error on failure.

### See Also

`load_hashmap`, `saveRDS`

### Examples

    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)

[Package hashmap version 0.2.2 Index]