storage.get.default

0th

Percentile

Get a value from a memory store.

Gets a value, for a given key, from the store.

If there is no coresponding value for the key, then NULL is returned.

Usage
# S3 method for default
storage.get(storage, key)
Arguments
storage

initialized storage

key

key to retrieve value for

Value

Stored value for the key, NULL otherwise.

Aliases
  • storage.get.default
Examples
# NOT RUN {
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!")
# }
Documentation reproduced from package memofunc, version 1.0.2, License: GPL-3

Community examples

Looks like there are no examples yet.