storage.init: Initialize a store.

Description Usage Arguments Value Examples

View source: R/storage.R

Description

Initlaize storage for name value pairs based on provided type.

Available types of storage include:

Additional paramters may be provided when initializing different types of storage.

See specific storage types for details.

Usage

1
storage.init(storage.type = "memory", ...)

Arguments

storage.type

storage type to initialize, defaults to memory

...

additional configuration values used by storage implementations

Value

List containing characteristics perticular to the storage implementation, including:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library(magrittr)

# initialize default memory storage
my.storage <- storage.init()

# set a value into storage
storage.set(my.storage, "name", "Roy Wetherall")

# .. and some more
my.storage %>% 
  storage.set("age", 45) %>% 
  storage.set("alive", TRUE) %>%
  storage.set("children", c("Peter", "Grace", "Lucy"))

# check a key has been set
if (storage.has(my.storage, "name")) print("I know your name!")

# .. and that a key hasn't been set
if (!storage.has(my.storage, "address")) print("I don't know where you live!")

# get some values from storage
sprintf(
  "%s is %i years old.", 
  storage.get(my.storage, "name"),
  storage.get(my.storage, "age"))

# remove a value from storage
storage.unset(my.storage, "children")

# .. and show it's not there anymore
if (!storage.has(my.storage, "address")) print("I don't know who your children are!")

# clear all values from storage
storage.clear(my.storage)

# .. and everything is gone
if (!storage.has(my.storage, "name") && !storage.has(my.storage, "age")) print("I know nothing!")

memofunc documentation built on Feb. 23, 2021, 1:06 a.m.