This hidden function appends a single tag (key-value pair) to the metadata of a cached object identified by its cacheId. Tags can be stored either in a database (via DBI) or in a file-based cache system.

Updates the value of an existing tag for a cached object identified by its cacheId. If the tag does not exist and add = TRUE, the tag will be added. This function supports both database-backed and file-based cache systems.

.addTagsRepo(
  cacheId,
  cachePath = getOption("reproducible.cachePath"),
  tagKey = character(),
  tagValue = character(),
  cacheSaveFormat = getOption("reproducible.cacheSaveFormat"),
  drv = getDrv(getOption("reproducible.drv", NULL)),
  conn = getOption("reproducible.conn", NULL),
  verbose = getOption("reproducible.verbose")
)

.updateTagsRepo(
  cacheId,
  cachePath = getOption("reproducible.cachePath"),
  tagKey = character(),
  tagValue = character(),
  add = TRUE,
  cacheSaveFormat = getOption("reproducible.cacheSaveFormat"),
  drv = getDrv(getOption("reproducible.drv", NULL)),
  conn = getOption("reproducible.conn", NULL),
  verbose = getOption("reproducible.verbose")
)

Arguments

cacheId

character(1) Unique identifier of the cached object. Must be of length 1.

cachePath

character(1) Path to the cache directory. Defaults to getOption("reproducible.cachePath").

tagKey

character(1) The key for the tag. Must be supplied.

tagValue

character(1) The new value for the tag. Must be supplied.

cacheSaveFormat

character(1) Format used for saving cache files. Defaults to getOption("reproducible.cacheSaveFormat").

drv

A DBI driver object. Defaults to getDrv(getOption("reproducible.drv", NULL)).

conn

A DBI connection object. If NULL, a new connection is created internally.

verbose

integer or logical. If > 0 or TRUE, print informational messages. Defaults to getOption("reproducible.verbose").

add

logical(1) If TRUE, adds the tag if it does not exist. Defaults to TRUE.

Value

NULL (invisibly). The function is called for its side effects.

NULL (invisibly). Called for its side effects.

Details

This function is primarily used internally by the reproducible package to maintain metadata about cached objects. It supports both database-backed and file-based caching systems.

  • If useDBI() returns TRUE, the tag update is performed in the database table.

  • If no rows are affected and add = TRUE, the tag is inserted using .addTagsRepo().

  • For file-based caches, the function modifies the tag in the corresponding metadata file.

See also

.addTagsRepo() for adding tags without updating.

Examples

a <- Cache(rnorm(1))
#> No cachePath supplied and getOption('reproducible.cachePath') is inside a temporary directory;
#>   this will not persist across R sessions.
#> Object to retrieve (fn: rnorm, ca275879d5116967.rds) ...
#> Loaded! Cached result from previous rnorm call
.addTagsRepo(cacheId = gsub("cacheId:", "", attr(a, "tags")),
             tagKey = "status", tagValue = "processed")
#> [1] 493
showCache() # last entry is the above line
#> No cachePath supplied and getOption('reproducible.cachePath') is inside a temporary directory;
#>   this will not persist across R sessions.
#> Cache size:
#> Total (including Rasters): 26.5 Kb
#> Selected objects (not including Rasters): 26.5 Kb
#>              cacheId              tagKey                       tagValue
#>               <char>              <char>                         <char>
#>  1: a23e6daa3fc8bdc5            function prepInputs_fireSenseParams.rds
#>  2: a23e6daa3fc8bdc5            accessed      2026-08-25 19:41:55.54808
#>  3: a23e6daa3fc8bdc5             inCloud                          FALSE
#>  4: a23e6daa3fc8bdc5   elapsedTimeDigest               0.003142357 secs
#>  5: a23e6daa3fc8bdc5           preDigest          .FUN:02beb4f7734642e4
#>  6: a23e6daa3fc8bdc5           preDigest        enclos:4412a6633250beb8
#>  7: a23e6daa3fc8bdc5           preDigest         envir:d2c074244988e3b3
#>  8: a23e6daa3fc8bdc5           preDigest          expr:babfa29d70e92731
#>  9: a23e6daa3fc8bdc5               class                     data.frame
#> 10: a23e6daa3fc8bdc5         object.size                          28992
#> 11: a23e6daa3fc8bdc5            fromDisk                          FALSE
#> 12: a23e6daa3fc8bdc5          resultHash                               
#> 13: a23e6daa3fc8bdc5 elapsedTimeFirstRun                0.02567744 secs
#> 14: a23e6daa3fc8bdc5            accessed      2026-08-25 19:41:55.75495
#> 15: a23e6daa3fc8bdc5            accessed      2026-08-25 19:41:55.79984
#> 16: a23e6daa3fc8bdc5            accessed      2026-08-25 19:41:55.88054
#> 17: ca275879d5116967            function                          rnorm
#> 18: ca275879d5116967            accessed      2026-08-25 19:41:54.90974
#> 19: ca275879d5116967             inCloud                          FALSE
#> 20: ca275879d5116967   elapsedTimeDigest               0.003232241 secs
#> 21: ca275879d5116967           preDigest          .FUN:4f604aa46882b368
#> 22: ca275879d5116967           preDigest          mean:c40c00762a0dac94
#> 23: ca275879d5116967           preDigest             n:853b1797f54b229c
#> 24: ca275879d5116967           preDigest            sd:853b1797f54b229c
#> 25: ca275879d5116967               class                        numeric
#> 26: ca275879d5116967         object.size                             56
#> 27: ca275879d5116967            fromDisk                          FALSE
#> 28: ca275879d5116967          resultHash                               
#> 29: ca275879d5116967 elapsedTimeFirstRun              0.0009777546 secs
#> 30: ca275879d5116967            accessed      2026-08-25 19:41:57.66613
#> 31: ca275879d5116967              status                      processed
#> 32: d03daaa68c73e7e9            function                centralTendency
#> 33: d03daaa68c73e7e9            userTags                   thisIsUnique
#> 34: d03daaa68c73e7e9            userTags                   reallyUnique
#> 35: d03daaa68c73e7e9            accessed      2026-08-25 19:41:47.48472
#> 36: d03daaa68c73e7e9             inCloud                          FALSE
#> 37: d03daaa68c73e7e9   elapsedTimeDigest               0.001439333 secs
#> 38: d03daaa68c73e7e9           preDigest          .FUN:88d14fe75c352ad5
#> 39: d03daaa68c73e7e9           preDigest             x:e4aa8de28dc6c1bb
#> 40: d03daaa68c73e7e9               class                        numeric
#> 41: d03daaa68c73e7e9         object.size                             56
#> 42: d03daaa68c73e7e9            fromDisk                          FALSE
#> 43: d03daaa68c73e7e9          resultHash                               
#> 44: d03daaa68c73e7e9 elapsedTimeFirstRun                0.03735399 secs
#> 45: d03daaa68c73e7e9            accessed      2026-08-25 19:41:47.53803
#> 46: d598abd965f6e371            function                    sf::st_read
#> 47: d598abd965f6e371            accessed      2026-08-25 19:41:55.47816
#> 48: d598abd965f6e371             inCloud                          FALSE
#> 49: d598abd965f6e371   elapsedTimeDigest               0.002566576 secs
#> 50: d598abd965f6e371           preDigest          .FUN:322208b6a2fd2938
#> 51: d598abd965f6e371           preDigest           dsn:6071e082648497fe
#> 52: d598abd965f6e371               class                             sf
#> 53: d598abd965f6e371         object.size                          79296
#> 54: d598abd965f6e371            fromDisk                          FALSE
#> 55: d598abd965f6e371          resultHash                               
#> 56: d598abd965f6e371 elapsedTimeFirstRun                0.01845646 secs
#>              cacheId              tagKey                       tagValue
#>               <char>              <char>                         <char>
#>                    createdDate
#>                         <char>
#>  1: 2026-08-25 19:41:55.575745
#>  2: 2026-08-25 19:41:55.575745
#>  3: 2026-08-25 19:41:55.575745
#>  4: 2026-08-25 19:41:55.575745
#>  5: 2026-08-25 19:41:55.575745
#>  6: 2026-08-25 19:41:55.575745
#>  7: 2026-08-25 19:41:55.575745
#>  8: 2026-08-25 19:41:55.575745
#>  9: 2026-08-25 19:41:55.575745
#> 10: 2026-08-25 19:41:55.575745
#> 11: 2026-08-25 19:41:55.575745
#> 12: 2026-08-25 19:41:55.575745
#> 13: 2026-08-25 19:41:55.575745
#> 14: 2026-08-25 19:41:55.755046
#> 15: 2026-08-25 19:41:55.799938
#> 16: 2026-08-25 19:41:55.880633
#> 17: 2026-08-25 19:41:54.911758
#> 18: 2026-08-25 19:41:54.911758
#> 19: 2026-08-25 19:41:54.911758
#> 20: 2026-08-25 19:41:54.911758
#> 21: 2026-08-25 19:41:54.911758
#> 22: 2026-08-25 19:41:54.911758
#> 23: 2026-08-25 19:41:54.911758
#> 24: 2026-08-25 19:41:54.911758
#> 25: 2026-08-25 19:41:54.911758
#> 26: 2026-08-25 19:41:54.911758
#> 27: 2026-08-25 19:41:54.911758
#> 28: 2026-08-25 19:41:54.911758
#> 29: 2026-08-25 19:41:54.911758
#> 30: 2026-08-25 19:41:57.666222
#> 31: 2026-08-25 19:41:57.667992
#> 32: 2026-08-25 19:41:47.523103
#> 33: 2026-08-25 19:41:47.523103
#> 34: 2026-08-25 19:41:47.523103
#> 35: 2026-08-25 19:41:47.523103
#> 36: 2026-08-25 19:41:47.523103
#> 37: 2026-08-25 19:41:47.523103
#> 38: 2026-08-25 19:41:47.523103
#> 39: 2026-08-25 19:41:47.523103
#> 40: 2026-08-25 19:41:47.523103
#> 41: 2026-08-25 19:41:47.523103
#> 42: 2026-08-25 19:41:47.523103
#> 43: 2026-08-25 19:41:47.523103
#> 44: 2026-08-25 19:41:47.523103
#> 45: 2026-08-25 19:41:47.538124
#> 46: 2026-08-25 19:41:55.498077
#> 47: 2026-08-25 19:41:55.498077
#> 48: 2026-08-25 19:41:55.498077
#> 49: 2026-08-25 19:41:55.498077
#> 50: 2026-08-25 19:41:55.498077
#> 51: 2026-08-25 19:41:55.498077
#> 52: 2026-08-25 19:41:55.498077
#> 53: 2026-08-25 19:41:55.498077
#> 54: 2026-08-25 19:41:55.498077
#> 55: 2026-08-25 19:41:55.498077
#> 56: 2026-08-25 19:41:55.498077
#>                    createdDate
#>                         <char>

a <- Cache(rnorm(1))
#> No cachePath supplied and getOption('reproducible.cachePath') is inside a temporary directory;
#>   this will not persist across R sessions.
#> Object to retrieve (fn: rnorm, ca275879d5116967.rds) ...
#> Loaded! Cached result from previous rnorm call
# Update an existing tag
.updateTagsRepo(cacheId = gsub("cacheId:", "", attr(a, "tags")),
             tagKey = "status", tagValue = "second")
#> [1] 508

# Add a tag if it doesn't exist
.updateTagsRepo(cacheId = gsub("cacheId:", "", attr(a, "tags")),
             tagKey = "status", tagValue = "new", add = TRUE)
#> [1] 507