Skip to content

Commit

Permalink
clean up docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Ross committed Nov 28, 2023
1 parent b885884 commit 3c98c2c
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 91 deletions.
22 changes: 12 additions & 10 deletions R/get_file_version.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#' Get in files from versioned repository
#'
#' Fetches the contents of a file from a versioned repository - a local git
#' repository, a GitHub repository, or an S3 bucket. Always fetches the file
#' to a local cache and returns the path to it.
#' repository, a GitHub repository, or an S3 bucket. Always fetches the file to
#' a local cache and returns the path to it.
#'
#' @param path Path of a file relative to the git directory or bucket
#' @param ref A git commit SHA, tag, branch or other [revision
#' string](https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions):
#' such as "HEAD~1", "main@{2023-02-26 18:30:00}", or "branch@{yesterday}".
#' Can also be a [git2r::commit()] object. For S3 buckets, a VersionID.
#' Defaults to "HEAD", which also means the latest version in an S3 bucket.
#' such as `"HEAD~1"`, `"main@{2023-02-26 18:30:00}"`, or
#' `"branch@{yesterday}"`. Can also be a [git2r::commit()] object. For S3
#' buckets, a VersionID. Defaults to "HEAD", which also means the latest
#' version in an S3 bucket.
#' @param repo The repository to get the file from. This can be a local git
#' directory, a GitHub repository (URL or "owner/repo" string), or an S3 bucket
#' indicated by "s3://bucket-name". Defaults to the current working directory.
#' directory, a GitHub repository (URL or `"owner/repo"` string), or an S3
#' bucket indicated by "s3://bucket-name". Defaults to the current working
#' directory.
#' @param endpoint,region For S3 buckets, the endpoint and region of the bucket.
#' If NULL, the default endpoint and region in local config or environment variables are used.
#' (Usually `us-east-1` and `s3.amazonaws.com`.)
#' If NULL, the default endpoint and region in local config or environment
#' variables are used. (Usually `us-east-1` and `s3.amazonaws.com`.)
#' @export
#' @return A [path][fs::path()] to the file in the local cache.
#' @return A [path][fs::fs_path()] to the file in the local cache.
get_file_version <- function(path, ref = "HEAD", repo = ".", endpoint = NULL, region = NULL) {
if (!is_scalar_character(path)) {
stop("path must be a single string")
Expand Down
29 changes: 17 additions & 12 deletions R/tar_meta_version.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#' Read a target project's metadata from repository history
#'
#' This function extracts [targets metadata][targets::tar_meta()] from versioned history.
#' In most cases this is a git repository, but it can also be an S3 cloud bucket
#' for a project using cloud versioning and storing the metadata file in the cloud.
#' (See `repository_meta` in [targets::tar_option_set()]).
#' This function extracts [targets metadata][targets::tar_meta()] from versioned
#' history. In most cases this is a git repository, but it can also be an S3
#' cloud bucket for a project using cloud versioning and storing the metadata
#' file in the cloud. (See `repository_meta` in [targets::tar_option_set()]).
#'
#' @param ref A git commit SHA, tag, branch or other [revision
#' string](https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions):
#' such as "HEAD~1", "main@{2023-02-26 18:30:00}", or "branch@{yesterday}".
#' Can also be a [git2r::commit()] object. For S3 buckets, a VersionID.
#' Defaults to "HEAD", which also means the latest version in an S3 bucket.
#' @param store Path to the targets store within the project. Defaults to `"_targets`, or the current project's [store name][targets::tar_path_store()] if `repo = "."`.
#' such as `"HEAD~1"`, `"main@{2023-02-26 18:30:00}"`, or
#' `"branch@{yesterday}"`. Can also be a [git2r::commit()] object. For S3
#' buckets, a VersionID. Defaults to "HEAD", which also means the latest
#' version in an S3 bucket.
#' @param store Path to the targets store within the project. Defaults to
#' `"_targets`, or the current project's [store
#' name][targets::tar_path_store()] if `repo = "."`.
#' @param repo The repository to get the file from. This can be a local git
#' directory, a GitHub repository (URL or "owner/repo" string), or an S3 bucket
#' indicated by "s3://bucket-name". Defaults to the current working directory.
#' directory, a GitHub repository (URL or `"owner/repo"` string), or an S3
#' bucket indicated by "s3://bucket-name". Defaults to the current working
#' directory.
#' @param endpoint,region For S3 buckets, the endpoint and region of the bucket.
#' @param ... Arguments passed to [targets::tar_meta()]
#' @return A data frame with one row per target/object. See [targets::tar_meta()] for details.
#' @return A data frame with one row per target/object. See
#' [targets::tar_meta()] for details.
#' @export
tar_meta_version <- function(ref = "HEAD", store = NULL, repo = ".", endpoint = NULL, region = NULL, ...) {
tar_meta_version <- function(ref = "HEAD", repo = ".", store = NULL, endpoint = NULL, region = NULL, ...) {
check_installed("targets")
if (is.null(store)) {
store <- if (repo == ".") targets::tar_config_get("store") else "_targets"
Expand Down
46 changes: 26 additions & 20 deletions R/tar_read_version.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
#' Read a target's value from a git repository
#'
#' Reads the content of targets from a git repository. Target metadata and
#' local target files are extracted into a temporary directory before being
#' read in by `tar_read()`. For targets of type "file", the files are also
#' extracted and the paths to the extracted files are returned.
#' Reads the content of targets from a git repository. Target metadata and local
#' target files are extracted into a temporary directory before being read in by
#' `tar_read()`. For targets of type "file", the files are also extracted and
#' the paths to the extracted files are returned.
#'
#' For cloud targets, the target metadata is read from git history and then
#' this metadata is used to download the target from the cloud. For this to work,
#' For cloud targets, the target metadata is read from git history and then this
#' metadata is used to download the target from the cloud. For this to work,
#' cloud storage must be set up with versioning. Note that targets metadata
#' includes the bucket, endpoint, and region of a S3-stored target, but you must still
#' provide an AWS access key and secret as environment variables. If these differ
#' from the credentials used for your current project or environment, can use
#' [withr::with_envvar()] to temporarily set the credentials.
#' includes the bucket, endpoint, and region of a S3-stored target, but you must
#' still provide an AWS access key and secret as environment variables. If these
#' differ from the credentials used for your current project or environment, can
#' use [withr::with_envvar()] to temporarily set the credentials.
#'
#' @param name Name of the target. `tar_read_version()` can take a symbol, `tar_read_raw_version()` requires a character.
#' @param name Name of the target. `tar_read_version()` can take a symbol,
#' `tar_read_raw_version()` requires a character.
#' @param ref A git commit SHA, tag, branch or other [revision
#' string](https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions):
#' such as "HEAD~1", "main@{2023-02-26 18:30:00}", or "branch@{yesterday}".
#' Can also be a [git2r::commit()] object. For S3 buckets, a VersionID.
#' Defaults to "HEAD", which also means the latest version in an S3 bucket.
#' @param store Path to the targets store within the project. Defaults to `"_targets`, or the current project's [store name][targets::tar_path_store()] if `repo = "."`.
#' such as `"HEAD~1"`, `"main@{2023-02-26 18:30:00}"`, or
#' `"branch@{yesterday}"`. Can also be a [git2r::commit()] object. For S3
#' buckets, a VersionID. Defaults to "HEAD", which also means the latest
#' version in an S3 bucket.
#' @param store Path to the targets store within the project. Defaults to
#' `"_targets`, or the current project's [store
#' name][targets::tar_path_store()] if `repo = "."`.
#' @param repo The repository to get the file from. This can be a local git
#' directory, a GitHub repository (URL or "owner/repo" string), or an S3 bucket
#' indicated by "s3://bucket-name". Defaults to the current working directory.
#' directory, a GitHub repository (URL or `"owner/repo"` string), or an S3
#' bucket indicated by "s3://bucket-name". Defaults to the current working
#' directory.
#' @export
#' @return The target's value. If the target is of `format = "file"`, this will be the path to the file in the [relic cache][relic_cache()].
tar_read_version <- function(name, ref = "HEAD", repo = ".", store = targets::tar_path_store()) {
#' @return The target's value. If the target is of `format = "file"`, this will
#' be the path to the file in the [relic cache][relic_cache()].
tar_read_version <- function(name, ref = "HEAD", repo = ".", store = NULL) {
check_installed("targets")
name <- targets::tar_deparse_language(substitute(name))
tar_read_raw_version(name, ref, repo, store)
Expand All @@ -35,7 +41,7 @@ tar_read_version <- function(name, ref = "HEAD", repo = ".", store = targets::ta
#' @export
tar_read_raw_version <- function(name, ref = "HEAD", repo = ".", store = NULL) {
check_installed("targets")
meta <- tar_meta_version(ref = ref, store = store, repo = repo)
meta <- tar_meta_version(ref = ref, repo = repo, store = store)
path_store <- attr(meta, "path_store")
index <- meta$name == name
if (!any(index) || sum(index) > 1) {
Expand Down
22 changes: 12 additions & 10 deletions man/get_file_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/relic-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions man/tar_meta_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions man/tar_read_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c98c2c

Please sign in to comment.