From f235961b06ed089c880b5a07e9f428dbb89d65d0 Mon Sep 17 00:00:00 2001 From: Tan Date: Fri, 29 Dec 2023 15:48:34 -0500 Subject: [PATCH] update pb_download_url examples --- R/pb_download_url.R | 29 ++++++++++++++++++++++++++--- man/pb_download.Rd | 6 +++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/R/pb_download_url.R b/R/pb_download_url.R index af9bd77..79dce69 100644 --- a/R/pb_download_url.R +++ b/R/pb_download_url.R @@ -13,11 +13,34 @@ #' @examples \donttest{ #' \dontshow{try(\{} #' -#' # returns browser url by default -#' pb_download_url("iris.tsv.xz", repo = "cboettig/piggyback-tests", tag = "v0.0.1") +#' # returns browser url by default (and all files if none are specified) +#' browser_url <- pb_download_url( +#' repo = "tanho63/piggyback-tests", +#' tag = "v0.0.2" +#' ) +#' print(browser_url) +#' utils::read.csv(browser_url[[1]]) #' #' # can return api url if desired -#' pb_download_url("iris.tsv.xz", repo = "cboettig/piggyback-tests", tag = "v0.0.1", url_type = "api") +#' api_url <- pb_download_url( +#' "mtcars.csv", +#' repo = "tanho63/piggyback-tests", +#' tag = "v0.0.2" +#' ) +#' print(api_url) +#' +#' # for public repositories, this will still work +#' utils::read.csv(api_url) +#' +#' # for private repos, can use httr or curl to fetch and then pass into read function +#' gh_pat <- Sys.getenv("GITHUB_PAT") +#' +#' if(!identical(gh_pat, "")){ +#' resp <- httr::GET(api_url, httr::add_headers(Authorization = paste("Bearer", gh_pat))) +#' utils::read.csv(text = httr::content(resp, as = "text")) +#' } +#' +#' # or use pb_read which bundles some of this for you #' #' \dontshow{\})} #' } diff --git a/man/pb_download.Rd b/man/pb_download.Rd index 9b0b082..27ca0ab 100644 --- a/man/pb_download.Rd +++ b/man/pb_download.Rd @@ -45,7 +45,7 @@ Download data from an existing release } \examples{ \donttest{ - try({ # this try block is to avoid errors on CRAN, not needed for normal use +\dontshow{try(\{} ## Download a specific file. ## (if dest is omitted, will write to current directory) dest <- tempdir() @@ -63,8 +63,8 @@ Download data from an existing release dest = dest ) list.files(dest) - }) - \dontshow{ +\dontshow{\})} +\dontshow{ try(unlink(list.files(dest, full.names = TRUE))) } }