Skip to content

Commit

Permalink
pins infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Nov 22, 2024
1 parent b8ba981 commit f82e244
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^data-raw$
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
96 changes: 96 additions & 0 deletions R/pins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#' Return GitHub raw url
#'
#' @param x `<chr>` string
#'
#' @returns `<chr>` 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 `<chr>` `"local"` or `"remote"`
#'
#' @param package `<chr>` package name
#'
#' @returns `<pins_board_folder>` or `<pins_board_url>`
#'
#' @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 `<chr>` string name of pinned dataset
#'
#' @param ... additional arguments passed to `mount_board()`
#'
#' @returns `<tibble>` or `<data.frame>`
#'
#' @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 `<list>` of [pins][pins::pins-package]
#'
#' @autoglobal
#'
#' @importFrom pins pin_list
#'
#' @keywords internal
#'
#' @export
list_pins <- function(...) {

board <- mount_board(...)

pin_list(board)
}
45 changes: 45 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions man/get_pin.Rd

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

22 changes: 22 additions & 0 deletions man/gh_raw.Rd

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

18 changes: 18 additions & 0 deletions man/list_pins.Rd

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

20 changes: 20 additions & 0 deletions man/mount_board.Rd

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

0 comments on commit f82e244

Please sign in to comment.