library(stamp)
x <- data.frame(a = 1:5,
b = letters[1:5])stamp and digest
At the most basic level, {stamp} is a wrapper of the {digest} package which
creates hashed of arbitrary objects using different algorithms. This is
why, the most basic function of stamp, stamp_get(), which
is used by all the other functions of stamp, receives all the arguments
in digest::digest(). The main differences is that
stamp_get() returns a hash for every element of a list
object or a single hash of an atomic vector. In addition, it returns
some information about the time and date in which the hash was
calculated and the algorithm used.
# stamp of a data frame
stamp_get(x)
#> $stamps
#> $stamps$a
#> [1] "f8c70106cb55eb803d1ab78e093bc2d1"
#>
#> $stamps$b
#> [1] "5802b7a27d20ad9feb00616660d4c1e7"
#>
#>
#> $time
#> $time$tz
#> [1] "UTC"
#>
#> $time$tformat
#> [1] "%Y%m%d%H%M%S"
#>
#> $time$usetz
#> [1] FALSE
#>
#> $time$st_time
#> [1] "20230202223701"
#>
#>
#> $algo
#> [1] "spookyhash"
# stamp of an atomic vector
stamp_get(letters)
#> $stamps
#> $stamps[[1]]
#> [1] "b85e2561a4cab45b3798abcf32a54464"
#>
#>
#> $time
#> $time$tz
#> [1] "UTC"
#>
#> $time$tformat
#> [1] "%Y%m%d%H%M%S"
#>
#> $time$usetz
#> [1] FALSE
#>
#> $time$st_time
#> [1] "20230202223701"
#>
#>
#> $algo
#> [1] "spookyhash"Save the Stamp
Getting a stamp by itself is not very useful. The main idea of the stamp package is to keep track of an R object and find when in the process its data has changed. You can do it in two different but complementary ways. Either saving the stamps into memory or by saving the stamp in disk.
Set stamps
{stamp] allows you to save stamps into memory, making use of a
special environment call .stamp that is created each time
the {stamp} package is loaded. As long as you don’t restart your R
session, the objects saved in this environment will be available for
continuous use.
To save a stamp you use stamp_set(), which require the
object you want to stamp and, ideally, a name for the stamp. If you
don’t provide a name, stamp_set() will create a random name
for you. This is useful in no interactive sessions.
Call stamps
To avoid mistakes, {stamp] makes it difficult for you to access
directly the stamps saved on memory. If you need to call a stamp, the
best way to do is by using stamp_call()
stamp_call(st_name = "x_st")
#> $stamps
#> $stamps$a
#> [1] "f8c70106cb55eb803d1ab78e093bc2d1"
#>
#> $stamps$b
#> [1] "5802b7a27d20ad9feb00616660d4c1e7"
#>
#>
#> $time
#> $time$tz
#> [1] "UTC"
#>
#> $time$tformat
#> [1] "%Y%m%d%H%M%S"
#>
#> $time$usetz
#> [1] FALSE
#>
#> $time$st_time
#> [1] "20230202223702"
#>
#>
#> $algo
#> [1] "spookyhash"You don’t need to remember all the the stamps save into memory. You
can get all the names using stamps_env() . Notice that the
second name you see below is the random name generated above with
stamp_set(x = x).
stamp_env()
#> [1] "x_st" "caxe2n5u"