A session is a view of one snapshot. Read-only sessions are pinned to a
branch tip, tag or snapshot id; writable sessions start from a branch tip
and accumulate changes until ic_commit().
Usage
ic_session_readonly(repo, branch = NULL, tag = NULL, snapshot = NULL)
ic_session_writable(repo, branch = "main")
ic_session_info(session)Examples
ex <- ic_example_repo()
repo <- ic_repo_open(ex$path, authorize = ex$authorize)
# read the branch head, a tag, or a snapshot
s <- ic_session_readonly(repo, branch = "main")
ic_session_info(s)
#> $snapshot_id
#> [1] "3FN4TZJS1JCRJ91QETAG"
#>
#> $branch
#> [1] ""
#>
#> $mode
#> [1] "readonly"
#>
#> $read_only
#> [1] TRUE
#>
#> $is_fork
#> [1] FALSE
#>
#> $has_uncommitted_changes
#> [1] FALSE
#>
then <- ic_session_readonly(repo, tag = "v1")
ic_nodes(then)$path
#> [1] "/" "/from_bin" "/from_nc"
# a writable session collects changes until ic_commit()
w <- ic_session_writable(repo, "main")
ic_set(w, "zarr.json", charToRaw('{"zarr_format":3,"node_type":"group","attributes":{"edited":true}}'))
ic_session_info(w)$has_uncommitted_changes
#> [1] TRUE
ic_discard(w)
# one array's metadata at two tags of a real repository
oisst <- ic_repo_open(ic_example_oisst()$path)
units <- function(tag) {
meta <- ic_get(ic_session_readonly(oisst, tag = tag), "time/zarr.json")
jsonlite::fromJSON(rawToChar(meta))$attributes$units
}
units("as-virtualized")
#> NULL
units("cf-repaired")
#> [1] "days since 1978-01-01 12:00:00"