View source: R/pb_download_url.R
pb_download_url | R Documentation |
Returns the URL download for a given file. This can be useful when using functions that are able to accept URLs.
pb_download_url(
file = NULL,
repo = guess_repo(),
tag = "latest",
url_type = c("browser", "api"),
.token = gh::gh_token()
)
file |
character: vector of names of files to be downloaded. If |
repo |
string: GH repository name in format "owner/repo". Default |
tag |
string: tag for the GH release, defaults to "latest" |
url_type |
choice: one of "browser" or "api" - default "browser" is a web-facing URL that is not subject to API ratelimits but does not work for private repositories. "api" URLs work for private repos, but require a GitHub token passed in an Authorization header (see examples) |
.token |
GitHub authentication token, see |
the URL to download a file
# 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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.