Every function that takes a key accepts a string, a dastash_key, or any
value the canonical encoding covers. stash_key() builds a key from values;
stash_key_chr() returns the canonical text a key is stored under, and
stash_key_hash() its SHA-256.
A single string is its own text: "XSWX/2026-08-29" is stored under exactly
those bytes. Anything else — numbers, dates, vectors, lists, data frames, or
several values — is written in a specified text encoding in which field order
does not matter, 1L and 1 agree, and a timestamp's time zone is not part
of its identity. A string that begins like an encoded value ({, (, ~,
#, D{, or a type tag such as s:) is escaped so the two can never
collide.
Functions, environments, connections, S4 objects and external pointers have
no encoding and raise dastash_key_invalid.
stash_keys() lists keys as their text. A plain string key's text is the
string itself and can be passed back as it is, but a structured key's text,
such as "{n=i:1}", would be taken as a string. stash_key_text() turns a
listed text back into the key it lists.
Arguments
- ...
Values that make up the key: one unnamed value, or several values that are either all named or all unnamed. Named values are ordered by name, so their order does not matter. Supports
!!!to splice a list.- key
A string, a
dastash_key, or a value the encoding covers.- text
One key's text, as
stash_keys()orstash_key_chr()gives it.
Value
stash_key() and stash_key_text() return a dastash_key.
stash_key_chr() returns the canonical text as a string, and
stash_key_hash() the SHA-256 of that text as 64 lower-case hex
characters.
Examples
stash_key("XSWX/2026-08-29")
#> <dastash_key> XSWX/2026-08-29
k <- stash_key(exchange = "XSWX", date = as.Date("2026-08-29"))
k
#> <dastash_key> {date=d:2026-08-29,exchange=s:XSWX}
identical(k, stash_key(date = as.Date("2026-08-29"), exchange = "XSWX"))
#> [1] TRUE
stash_key_chr(list(n = 1L, p = 0.1))
#> [1] "{n=i:1,p=f:0x1.999999999999ap-4}"
stash_key_hash("XSWX/2026-08-29")
#> [1] "71700ef4036aa32ab0243e79eb67d400c264b1ea37e3c8cbdfc3ad129261e1cb"
# A listed structured key, used again.
s <- local_stash()
stash_set(s, list(n = 1), "one")
#> Error in stash_set(s, list(n = 1), "one"): This stash has been closed.
listed <- stash_keys(s)
#> Error in stash_keys(s): This stash has been closed.
listed
#> Error: object 'listed' not found
stash_get(s, stash_key_text(listed))
#> Error in stash_get(s, stash_key_text(listed)): This stash has been closed.