Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions R/get_github_file.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#' Read in a file from the NHP Outputs app GitHub repo
#' Read in a file from a Strategy Unit GitHub repo
#'
#' @param repo string. The name of the repository in which to find the file
#' @param folder string. The folder where the file is located. Set to `""` to
#' use the root folder of the repo.
#' @param file string. The name of the file to read in
#' @param folder string. The folder where the file is located. `"inst"` by
#' default. Set to `""` to use the root folder of the repo.
#' @returns The file contents as a stream, to be passed to a reader function
#' @keywords internal
get_outputs_gh_file <- function(file, folder = "inst") {
get_su_gh_file <- function(repo, folder, file) {
httr2::request("https://api.github.com") |>
httr2::req_url_path_append("repos") |>
httr2::req_url_path_append("The-Strategy-Unit") |>
httr2::req_url_path_append("nhp_outputs") |>
httr2::req_url_path_append(repo) |>
httr2::req_url_path_append("contents") |>
httr2::req_url_path_append(folder) |>
httr2::req_url_path_append(file) |>
Expand All @@ -21,28 +22,22 @@ get_outputs_gh_file <- function(file, folder = "inst") {
}


#' Read in a file from the TPMAs GitHub repo
#' Read in a file from the NHP Outputs app GitHub repo
#'
#' @param file string. The name of the file to read in
#' @param folder string. The folder where the file is located. `"reference"` by
#' default. Set to `""` to use the root folder of the repo.
#' @returns The file contents as a stream, to be passed to a reader function
#' @param ... Pass the name of the file in via `...`
#' @keywords internal
get_tpmas_gh_file <- function(file, folder = "reference") {
httr2::request("https://api.github.com") |>
httr2::req_url_path_append("repos") |>
httr2::req_url_path_append("The-Strategy-Unit") |>
httr2::req_url_path_append("TPMAs") |>
httr2::req_url_path_append("contents") |>
httr2::req_url_path_append(folder) |>
httr2::req_url_path_append(file) |>
httr2::req_perform() |>
httr2::resp_check_status() |>
httr2::resp_body_json() |>
purrr::pluck("content") |>
base64enc::base64decode()
get_outputs_gh_file <- function(...) {
purrr::partial(get_su_gh_file, repo = "nhp_outputs", folder = "inst")(...)
}


#' Read in a file from the TPMAs GitHub repo
#'
#' @inheritParams get_outputs_gh_file
#' @keywords internal
get_tpmas_gh_file <- function(...) {
purrr::partial(get_su_gh_file, repo = "TPMAs", folder = "reference")(...)
}

possibly_get_outputs_gh_file <- \(...) purrr::possibly(get_outputs_gh_file)(...)
possibly_get_tpmas_gh_file <- \(...) purrr::possibly(get_tpmas_gh_file)(...)
10 changes: 2 additions & 8 deletions man/get_outputs_gh_file.Rd

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

23 changes: 23 additions & 0 deletions man/get_su_gh_file.Rd

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

10 changes: 2 additions & 8 deletions man/get_tpmas_gh_file.Rd

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