Using Aliases with stamp

Overview

Aliases let you work with multiple, independent stamp folders in a single R session. An alias is a selector for which folder configuration to use; it does not change any on-disk paths. All artifact paths remain the same regardless of alias; aliases select the folder configuration for the catalog and versions, not the session options.

Storage model (v0.0.9+): Artifacts are stored as <root>/<path>/<filename>/<filename> with version history in <root>/<path>/<filename>/versions/. The .stamp/ directory within each aliased root contains only state (catalog, locks, temp files).

Key properties:

  • Aliases select a specific stamp folder initialized via st_init().
  • Paths never include alias segments; alias affects catalog/versions only.
  • Reusing one alias for different folders errors.
  • Different aliases pointing to the same folder warn; they share the same catalog/versions.
  • Back-compat alias "default" exists and can be re-based with st_switch().

Setup

Initialize one or more stamp folders and give each an alias:

root_a <- tempfile("projA-")
root_b <- tempfile("projB-")
alias_a <- basename(root_a)
alias_b <- basename(root_b)

# Note: st_init() creates the folder if missing
st_init(root_a, alias = alias_a)
#> ✔ stamp initialized
#>   alias: projA-b5646bad3c
#>   root: /tmp/RtmpCXgvOI/projA-b5646bad3c
#>   state: /tmp/RtmpCXgvOI/projA-b5646bad3c/.stamp
st_init(root_b, alias = alias_b)
#> ✔ stamp initialized
#>   alias: projB-b566066d2ff
#>   root: /tmp/RtmpCXgvOI/projB-b566066d2ff
#>   state: /tmp/RtmpCXgvOI/projB-b566066d2ff/.stamp

# Inspect what was created
fs::dir_tree(fs::path(root_a, ".stamp"), recurse = TRUE, all = TRUE)
#> /tmp/RtmpCXgvOI/projA-b5646bad3c/.stamp
#> ├── logs
#> └── temp
fs::dir_tree(fs::path(root_b, ".stamp"), recurse = TRUE, all = TRUE)
#> /tmp/RtmpCXgvOI/projB-b566066d2ff/.stamp
#> ├── logs
#> └── temp

You can inspect registered aliases:

st_alias_list()
#>                        alias                                       root
#> 1  stamp-request-b5632cd1dc8  /tmp/RtmpCXgvOI/stamp-request-b5632cd1dc8
#> 2          projB-b566066d2ff          /tmp/RtmpCXgvOI/projB-b566066d2ff
#> 3                    default   /tmp/RtmpCXgvOI/stamp-hashing-b56711b2d8
#> 4 stamp-metadata-b565babe4d8 /tmp/RtmpCXgvOI/stamp-metadata-b565babe4d8
#> 5           projA-b5646bad3c           /tmp/RtmpCXgvOI/projA-b5646bad3c
#>   state_dir                                        stamp_path
#> 1    .stamp  /tmp/RtmpCXgvOI/stamp-request-b5632cd1dc8/.stamp
#> 2    .stamp          /tmp/RtmpCXgvOI/projB-b566066d2ff/.stamp
#> 3    .stamp   /tmp/RtmpCXgvOI/stamp-hashing-b56711b2d8/.stamp
#> 4    .stamp /tmp/RtmpCXgvOI/stamp-metadata-b565babe4d8/.stamp
#> 5    .stamp           /tmp/RtmpCXgvOI/projA-b5646bad3c/.stamp
# Get alias details
st_alias_get(alias_a)
#> $root
#> /tmp/RtmpCXgvOI/projA-b5646bad3c
#> 
#> $state_dir
#> [1] ".stamp"
#> 
#> $stamp_path
#> /tmp/RtmpCXgvOI/projA-b5646bad3c/.stamp

Saving and Loading with Aliases

Use the same artifact path patterns; pass alias to select which catalog/versions apply:

pA <- fs::path(root_a, "data.qs")
pB <- fs::path(root_b, "data.qs")

# Save different data to A and B to ensure versions are created
st_save(data.frame(id = 1:2), pA, alias = alias_a)
#> ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/projA-b5646bad3c/data.qs' @ version
#>   ac1d3eb3d2156bbd
st_save(data.frame(id = 3:4), pB, alias = alias_b)
#> ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/projB-b566066d2ff/data.qs' @ version
#>   d6f6c2c39143727d

# Each alias has its own version history
st_versions(pA, alias = alias_a)
st_versions(pB, alias = alias_b)

# Loading respects the alias
objA <- st_load(pA, alias = alias_a)
#> Warning: No primary key recorded for '/tmp/RtmpCXgvOI/projA-b5646bad3c/data.qs'.
#> ℹ You can add one with `st_add_pk()`.
#> ✔ Loaded [qs2] ← '/tmp/RtmpCXgvOI/projA-b5646bad3c/data.qs'
objB <- st_load(pB, alias = alias_b)
#> Warning: No primary key recorded for '/tmp/RtmpCXgvOI/projB-b566066d2ff/data.qs'.
#> ℹ You can add one with `st_add_pk()`.
#> ✔ Loaded [qs2] ← '/tmp/RtmpCXgvOI/projB-b566066d2ff/data.qs'
list(A = objA, B = objB)
#> $A
#>   id
#> 1  1
#> 2  2
#> 
#> $B
#>   id
#> 1  3
#> 2  4

# Inspect what was created within the stamp folders
# Note: Artifacts are stored as <root>/<path>/<filename>/<filename>
# with versions in <root>/<path>/<filename>/versions/
cat("\nStructure in root_a:\n")
#> 
#> Structure in root_a:
fs::dir_tree(root_a, recurse = 2)
#> /tmp/RtmpCXgvOI/projA-b5646bad3c
#> └── data.qs
#>     ├── data.qs
#>     ├── data.qs.lock
#>     ├── stmeta
#>     │   └── data.qs.stmeta.json
#>     └── versions
#>         └── ac1d3eb3d2156bbd

cat("\nStructure in root_b:\n")
#> 
#> Structure in root_b:
fs::dir_tree(root_b, recurse = 2)
#> /tmp/RtmpCXgvOI/projB-b566066d2ff
#> └── data.qs
#>     ├── data.qs
#>     ├── data.qs.lock
#>     ├── stmeta
#>     │   └── data.qs.stmeta.json
#>     └── versions
#>         └── d6f6c2c39143727d

Version resolution is non-interactive. NULL or 0 resolve to the latest version:

# Load latest (using default version = NULL for latest)
latestA <- st_load(pA, alias = alias_a)
#> Warning: No primary key recorded for '/tmp/RtmpCXgvOI/projA-b5646bad3c/data.qs'.
#> ℹ You can add one with `st_add_pk()`.
#> ✔ Loaded [qs2] ← '/tmp/RtmpCXgvOI/projA-b5646bad3c/data.qs'
latestB <- st_load(pB, alias = alias_b)
#> Warning: No primary key recorded for '/tmp/RtmpCXgvOI/projB-b566066d2ff/data.qs'.
#> ℹ You can add one with `st_add_pk()`.
#> ✔ Loaded [qs2] ← '/tmp/RtmpCXgvOI/projB-b566066d2ff/data.qs'

list(latestA = latestA, latestB = latestB)
#> $latestA
#>   id
#> 1  1
#> 2  2
#> 
#> $latestB
#>   id
#> 1  3
#> 2  4

Switching the Default Alias

The special alias "default" exists for backward compatibility. You can re-base it to point at any initialized folder and keep legacy state in sync:

# Re-base default to alias A's folder (silent)
st_switch(alias_a)

# Now calls without alias use whatever folder default points to
st_save(data.frame(id = 5), fs::path(root_a, "more.qs"))
#> ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/projA-b5646bad3c/more.qs' @ version
#>   0761234df24e1d8d

Constraints and Conflicts

  • Reusing the same alias for two different folders errors during st_init().
  • Pointing two different aliases to the same folder warns; both operate on the same underlying catalog/versions.
  • Aliases are case-sensitive and trimmed; prefer simple names (letters, digits, _, -).

Best Practices

  • Keep per-project aliases (A, B, or project codes) and avoid reassigning them.
  • Store the alias choice alongside project scripts to make intent explicit.
  • Use st_switch() sparingly; explicit alias = in calls is clearer in shared code.
  • Version resolution: pass explicit version ids when pinning; use 0 for latest.

Troubleshooting

  • “alias conflict” error: You tried to reuse an alias for a different folder. Pick a new alias or re-point the original alias only if you intend to share catalogs.
  • “same folder” warning: Two aliases target the same folder; this is allowed but both will share catalog/versions.
  • Latest not loading: Ensure you passed version = 0 or NULL; loading without version loads the current version by default.

Notes

  • Internally, stamp maintains a catalog with an index for lineage (parents_index) to make reverse lookups fast. Aliases do not change filesystem layout; they only select which catalog is used.
  • Options like retention, verification, and primary key policies apply to the session. Configure them with st_opts(); aliases select folders, not option sets.
  • Storage architecture (v0.0.9+): Each aliased root stores:
    • .stamp/ - state only (catalog, locks, temp)
    • <path>/<filename>/ - artifact directories containing:
      • <filename> - the actual file
      • stmeta/ - sidecar metadata
      • versions/ - version history for that specific artifact