tar_git_checkout {gittargets} | R Documentation |
Check out a snapshot of the data (Git)
Description
Check out a snapshot of the data associated with
a particular code commit (default: HEAD
).
Usage
tar_git_checkout(
ref = "HEAD",
code = getwd(),
store = targets::tar_config_get("store"),
force = FALSE,
verbose = TRUE
)
Arguments
ref |
Character of length 1. SHA1 hash, branch name,
or other reference in the code repository
that points to a code commit. (You can also identify the code
commit by supplying a data branch of the form Once the desired code commit is identified,
If |
code |
Character of length 1, directory path to the code repository,
usually the root of the |
store |
Character of length 1, path to the data store of the pipeline.
If |
force |
ignore conflicts and overwrite modified files |
verbose |
Logical of length 1, whether to print R console messages confirming that a snapshot was created. |
Value
Nothing (invisibly).
See Also
Other git:
tar_git_init()
,
tar_git_log()
,
tar_git_ok()
,
tar_git_snapshot()
,
tar_git_status_code()
,
tar_git_status_data()
,
tar_git_status_targets()
,
tar_git_status()
Examples
if (Sys.getenv("TAR_EXAMPLES") == "true" && tar_git_ok(verbose = FALSE)) {
targets::tar_dir({ # Containing code does not modify the user's filespace.
# Work on an initial branch.
targets::tar_script(tar_target(data, "old_data"))
targets::tar_make()
targets::tar_read(data) # "old_data"
gert::git_init()
gert::git_add("_targets.R")
gert::git_commit("First commit")
gert::git_branch_create("old_branch")
tar_git_init()
# Work on a new branch.
tar_git_snapshot(status = FALSE, verbose = FALSE)
targets::tar_script(tar_target(data, "new_data"))
targets::tar_make()
targets::tar_read(data) # "new_data"
gert::git_branch_create("new_branch")
gert::git_add("_targets.R")
gert::git_commit("Second commit")
tar_git_snapshot(status = FALSE, verbose = FALSE)
# Go back to the old branch.
gert::git_branch_checkout("old_branch")
# The target is out of date because we only reverted the code.
targets::tar_outdated()
# But tar_git_checkout() lets us restore the old version of the data!
tar_git_checkout()
targets::tar_read(data) # "old_data"
# Now, the target is up to date! And we did not even have to rerun it!
targets::tar_outdated()
})
}