List directories, html-URLs and download-URLs in a GitHub directory.

ghr_ls(path, ..., regexp = NULL, ignore.case = FALSE, invert = FALSE)

ghr_ls_html_url(path, ..., regexp = NULL, ignore.case = FALSE,
  invert = FALSE)

ghr_ls_download_url(path, ..., regexp = NULL, ignore.case = FALSE,
  invert = FALSE)

Arguments

path

A string formatted as "owner/repo/subdir" or "owner/repo/subdir@branch", e.g.: "maurolepore/ghr/reference@gh-pages".

...

Arguments passed to gh::gh() via ghr_get().

regexp

A regular expression (e.g. [.]csv$) passed on to grep() to filter paths.

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

invert

logical. If TRUE return indices or values for elements that do not match.

Value

A character string.

Examples

path <- "maurolepore/tor/inst/extdata/mixed" # The first call make the request system.time(ghr_ls(path))
#> user system elapsed #> 0.020 0.000 0.105
# Takes no time because the first call is memoised system.time(ghr_ls(path))
#> user system elapsed #> 0.000 0.000 0.001
ghr_ls(path, regexp = "[.]csv$")
#> [1] "inst/extdata/mixed/csv.csv"
ghr_ls(path, regexp = "[.]csv$", invert = TRUE)
#> [1] "inst/extdata/mixed/lower_rdata.rdata" #> [2] "inst/extdata/mixed/rda.rda" #> [3] "inst/extdata/mixed/upper_rdata.RData"
ghr_ls(path, regexp = "[.]RDATA$", invert = TRUE, ignore.case = FALSE)
#> [1] "inst/extdata/mixed/csv.csv" #> [2] "inst/extdata/mixed/lower_rdata.rdata" #> [3] "inst/extdata/mixed/rda.rda" #> [4] "inst/extdata/mixed/upper_rdata.RData"
ghr_ls(path, regexp = "[.]RDATA$", invert = TRUE, ignore.case = TRUE)
#> [1] "inst/extdata/mixed/csv.csv" "inst/extdata/mixed/rda.rda"
# ghr_ls_download_url() and ghr_ls_html_url are similar (d_url <- ghr_ls_download_url(path, regexp = "[.]csv$")[[1]])
#> [1] "https://raw.githubusercontent.com/maurolepore/tor/master/inst/extdata/mixed/csv.csv"
read.csv(d_url)
#> y #> 1 a #> 2 b
(h_url <- ghr_ls_html_url(path, regexp = "[.]csv$")[[1]])
#> [1] "https://github.com/maurolepore/tor/blob/master/inst/extdata/mixed/csv.csv"
if (interactive()) { utils::browseURL(h_url) }