From f82e244943fd92f8c799e926818ef4a9b6215b62 Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Fri, 22 Nov 2024 01:13:34 -0800 Subject: [PATCH] pins infrastructure --- .Rbuildignore | 1 + DESCRIPTION | 4 ++ NAMESPACE | 10 +++++ R/pins.R | 96 ++++++++++++++++++++++++++++++++++++++++++++++ _pkgdown.yml | 45 ++++++++++++++++++++++ man/get_pin.Rd | 20 ++++++++++ man/gh_raw.Rd | 22 +++++++++++ man/list_pins.Rd | 18 +++++++++ man/mount_board.Rd | 20 ++++++++++ 9 files changed, 236 insertions(+) create mode 100644 R/pins.R create mode 100644 man/get_pin.Rd create mode 100644 man/gh_raw.Rd create mode 100644 man/list_pins.Rd create mode 100644 man/mount_board.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 6863c6f..844863e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^data-raw$ diff --git a/DESCRIPTION b/DESCRIPTION index 77610af..91b3eee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,6 +9,10 @@ License: MIT + file LICENSE URL: https://github.com/andrewallenbruce/arktax, https://andrewallenbruce.github.io/arktax/ BugReports: https://github.com/andrewallenbruce/arktax/issues +Imports: + fs, + glue, + pins Suggests: roxyglobals, testthat (>= 3.0.0) diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..4fefc29 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,12 @@ # Generated by roxygen2: do not edit by hand +export(get_pin) +export(gh_raw) +export(list_pins) +export(mount_board) +importFrom(fs,path_package) +importFrom(glue,glue) +importFrom(pins,board_folder) +importFrom(pins,board_url) +importFrom(pins,pin_list) +importFrom(pins,pin_read) diff --git a/R/pins.R b/R/pins.R new file mode 100644 index 0000000..c36efe3 --- /dev/null +++ b/R/pins.R @@ -0,0 +1,96 @@ +#' Return GitHub raw url +#' +#' @param x `` string +#' +#' @returns `` GitHub raw url +#' +#' @examples +#' gh_raw("andrewbruce/example/main/inst/pins/") +#' +#' @autoglobal +#' +#' @keywords internal +#' +#' @export +gh_raw <- function(x) { + paste0("https://raw.githubusercontent.com/", x) +} + +#' Mount [pins][pins::pins-package] board +#' +#' @param source `` `"local"` or `"remote"` +#' +#' @param package `` package name +#' +#' @returns `` or `` +#' +#' @autoglobal +#' +#' @importFrom pins board_folder board_url +#' @importFrom fs path_package +#' @importFrom glue glue +#' +#' @keywords internal +#' +#' @export +mount_board <- function(source = c("local", "remote"), package = "arktax") { + + source <- match.arg(source) + + switch( + source, + local = board_folder( + path_package("extdata/pins", package = package) + ), + remote = board_url( + gh_raw( + glue("andrewallenbruce/{package}/master/inst/extdata/pins/") + ) + ), + stop("Invalid source") + ) +} + +#' Get a pinned dataset from a [pins][pins::pins-package] board +#' +#' @param pin `` string name of pinned dataset +#' +#' @param ... additional arguments passed to `mount_board()` +#' +#' @returns `` or `` +#' +#' @autoglobal +#' +#' @importFrom pins pin_read +#' +#' @keywords internal +#' +#' @export +get_pin <- function(pin, ...) { + + board <- mount_board(...) + + pin <- match.arg(pin, list_pins()) + + pin_read(board, pin) +} + +#' List pins from a [pins][pins::pins-package] board +#' +#' @param ... arguments to pass to [mount_board()] +#' +#' @returns `` of [pins][pins::pins-package] +#' +#' @autoglobal +#' +#' @importFrom pins pin_list +#' +#' @keywords internal +#' +#' @export +list_pins <- function(...) { + + board <- mount_board(...) + + pin_list(board) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 7dbce06..8ece533 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,49 @@ url: https://andrewallenbruce.github.io/arktax/ + template: bootstrap: 5 + light-switch: true + bslib: + base_font: {google: "Roboto"} + heading_font: {google: "Roboto Slab"} + code_font: {google: "Source Code Pro"} +navbar: + structure: + left: + - intro + - reference + - articles + - tutorials + - news + right: + - search + - github + - lightswitch + components: + reference: + text: Reference + href: reference/index.html + search: + search: [] + lightswitch: + icon: fa-sun + aria-label: Light switch + id: lightswitch + menu: + - text: Light + theme: light + icon: fa-sun + - text: Dark + theme: dark + icon: fa-moon + - text: Auto + theme: auto + icon: fa-adjust + news: + text: Changelog + href: news/index.html + github: + icon: fab fa-github fa-lg + href: https://github.com/andrewallenbruce/arktax/ + aria-label: GitHub diff --git a/man/get_pin.Rd b/man/get_pin.Rd new file mode 100644 index 0000000..b4948bc --- /dev/null +++ b/man/get_pin.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{get_pin} +\alias{get_pin} +\title{Get a pinned dataset from a \link[pins:pins-package]{pins} board} +\usage{ +get_pin(pin, ...) +} +\arguments{ +\item{pin}{\verb{} string name of pinned dataset} + +\item{...}{additional arguments passed to \code{mount_board()}} +} +\value{ +\verb{} or \verb{} +} +\description{ +Get a pinned dataset from a \link[pins:pins-package]{pins} board +} +\keyword{internal} diff --git a/man/gh_raw.Rd b/man/gh_raw.Rd new file mode 100644 index 0000000..25000e9 --- /dev/null +++ b/man/gh_raw.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{gh_raw} +\alias{gh_raw} +\title{Return GitHub raw url} +\usage{ +gh_raw(x) +} +\arguments{ +\item{x}{\verb{} string} +} +\value{ +\verb{} GitHub raw url +} +\description{ +Return GitHub raw url +} +\examples{ +gh_raw("andrewbruce/example/main/inst/pins/") + +} +\keyword{internal} diff --git a/man/list_pins.Rd b/man/list_pins.Rd new file mode 100644 index 0000000..b11d7e6 --- /dev/null +++ b/man/list_pins.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{list_pins} +\alias{list_pins} +\title{List pins from a \link[pins:pins-package]{pins} board} +\usage{ +list_pins(...) +} +\arguments{ +\item{...}{arguments to pass to \code{\link[=mount_board]{mount_board()}}} +} +\value{ +\verb{} of \link[pins:pins-package]{pins} +} +\description{ +List pins from a \link[pins:pins-package]{pins} board +} +\keyword{internal} diff --git a/man/mount_board.Rd b/man/mount_board.Rd new file mode 100644 index 0000000..2a5d109 --- /dev/null +++ b/man/mount_board.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{mount_board} +\alias{mount_board} +\title{Mount \link[pins:pins-package]{pins} board} +\usage{ +mount_board(source = c("local", "remote"), package = "arktax") +} +\arguments{ +\item{source}{\verb{} \code{"local"} or \code{"remote"}} + +\item{package}{\verb{} package name} +} +\value{ +\verb{} or \verb{} +} +\description{ +Mount \link[pins:pins-package]{pins} board +} +\keyword{internal}