Skip to content

Commit

Permalink
chore: regen files
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-b committed Sep 17, 2024
1 parent 58cc69e commit 21edf83
Show file tree
Hide file tree
Showing 81 changed files with 11,064 additions and 10,139 deletions.
54 changes: 36 additions & 18 deletions R/pkgpins.gen.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See `README.md#r-markdown-format` for more information on the literate programming approach used applying the R Markdown format.

# pkgpins: Facilitates Results Caching in R Packages Using the Pins Package
# Copyright (C) 2023 Salim Brüggemann
# Copyright (C) 2024 Salim Brüggemann
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or any later version.
Expand Down Expand Up @@ -70,14 +70,18 @@ ls_board_paths <- function(pkg) {
#' # itself never uses the cache)
#' this_pkg <- "pkgpins"
#'
#' # let's define a fn that returns R pkg sys deps from cache
#' # let's define a fn that returns R pkg sys deps, cached
#' pkg_sys_deps <- function(pkg,
#' os = "ubuntu",
#' os_version = "24.04",
#' use_cache = TRUE,
#' max_cache_age = "6h") {
#' pkgpins::with_cache(
#' expr = purrr::list_flatten(jsonlite::fromJSON(txt = paste0("https://sysreqs.r-hub.io/pkg/",
#' pkg),
#' simplifyVector = FALSE)),
#' expr = purrr::list_flatten(jsonlite::fromJSON(
#' txt = glue::glue("https://packagemanager.posit.co/__api__/repos/2/sysreqs",
#' "?all=false&pkgname={pkg}&distribution={os}&release={os_version}"),
#' simplifyVector = FALSE
#' )),
#' pkg = this_pkg,
#' from_fn = "pkg_sys_deps",
#' pkg,
Expand Down Expand Up @@ -195,18 +199,28 @@ cachely <- function(pkg,
max_cache_age = "1 day") {

checkmate::assert_function(fn)
fn_fmls_syms <- rlang::fn_fmls_syms(fn)

# ensure fn doesn't already have caching params
caching_params <- c("use_cache", "max_cache_age")

if (any(caching_params %in% names(fn_fmls_syms))) {
cli::cli_abort("{.arg fn} mustn't already have {.or {.arg {caching_params}}} parameters.")
}

rlang::new_function(args = rlang::pairlist2(... = ,
!!!rlang::exprs(use_cache = !!use_cache,
max_cache_age = !!max_cache_age)),
body = rlang::expr(expr = with_cache(expr = do.call(what = !!fn,
list(...)),
pkg = !!pkg,
from_fn = !!fn_name,
...,
pkg_versioned = !!pkg_versioned,
use_cache = use_cache,
max_cache_age = max_cache_age)),
# create version of `fn` with caching
rlang::new_function(args = c(rlang::fn_fmls(fn = fn),
list(use_cache = use_cache,
max_cache_age = max_cache_age)),
body = rlang::expr(expr = pkgpins::with_cache(expr = do.call(what = !!fn,
args = !!fn_fmls_syms),
pkg = !!pkg,
from_fn = !!fn_name,
!!!unlist(x = fn_fmls_syms,
use.names = FALSE),
pkg_versioned = !!pkg_versioned,
use_cache = use_cache,
max_cache_age = max_cache_age)),
env = parent.frame(n = 2L))
}

Expand Down Expand Up @@ -468,13 +482,15 @@ is_cached <- function(board,
#'
#' # let's define a fn that returns R pkg sys deps from cache
#' pkg_sys_deps <- function(pkg,
#' os = "ubuntu",
#' os_version = "24.04",
#' use_cache = TRUE,
#' max_cache_age = "6h") {
#' fetch <- TRUE
#'
#' if (use_cache) {
#' pin_name <- pkgpins::hash_fn_call(from_fn = "pkg_sys_deps",
#' pkg)
#' pkg, os, os_version)
#' result <- pkgpins::get_obj(board = board,
#' id = pin_name,
#' max_age = max_cache_age)
Expand All @@ -483,7 +499,9 @@ is_cached <- function(board,
#'
#' if (fetch) {
#' result <-
#' jsonlite::fromJSON(txt = paste0("https://sysreqs.r-hub.io/pkg/", pkg),
#' jsonlite::fromJSON(txt = glue::glue("https://packagemanager.posit.co/__api__/repos/2/sysreqs",
#' "?all=false&pkgname={pkg}&distribution={os}",
#' "&release={os_version}"),
#' simplifyVector = FALSE) |>
#' purrr::list_flatten()
#' }
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ This package borrows a lot of the [Tidyverse](https://www.tidyverse.org/) design

- R source code is *not* split over several files as [suggested by the TSG](https://style.tidyverse.org/package-files.html) but instead is (as far as possible) kept in the single file [`Rmd/pkgpins.Rmd`](https://gitlab.com/rpkg.dev/pkgpins/-/tree/master/Rmd/pkgpins.Rmd) which is well-structured thanks to its [Markdown support](#r-markdown-format).

As far as possible, these deviations from the TSG plus some additional restrictions are formally specified in the [lintr configuration file](https://github.com/jimhester/lintr#project-configuration) [`.lintr`](.lintr), so lintr can be used right away to check for formatting issues:

``` r
pkgpurl::lint_rmd()
```
As far as possible, these deviations from the TSG plus some additional restrictions are formally specified in [`pkgpurl::default_linters`](https://pkgpurl.rpkg.dev/reference/default_linters), which is (by default) used in [`pkgpurl::lint_rmd()`](https://pkgpurl.rpkg.dev/reference/lint_rmd), which in turn is the recommended way to lint this package.

## See also

Expand All @@ -102,7 +98,7 @@ pkgpurl::lint_rmd()

[^1]: Support for dynamic inline R code was introduced in [roxygen2 7.1.0](https://www.tidyverse.org/blog/2020/03/roxygen2-7-1-0/).

[^2]: This naming convention as well as the very idea to leverage the R Markdown format to author R packages was originally proposed by Yihui Xie. See his excellent [blog post](https://yihui.name/rlp/) for more detailed information about the benefits of literate programming techniques and some practical examples. Note that using `pkgpurl::purl_rmd()` is a less cumbersome alternative to the Makefile approach outlined by him.
[^2]: The very idea to leverage the R Markdown format to author R packages was originally proposed by Yihui Xie. See his excellent [blog post](https://yihui.name/rlp/) for his point of view on the advantages of literate programming techniques and some practical examples. Note that using `pkgpurl::purl_rmd()` is a less cumbersome alternative to the Makefile approach outlined by him.

[^3]: The TSG [explicitly instructs to avoid this operator](https://style.tidyverse.org/pipes.html#assignment-2) – presumably because it’s relatively unknown and therefore might be confused with the forward pipe operator `%>%` when skimming code only briefly. I don’t consider this to be an actual issue since there aren’t many sensible usage patterns of `%>%` at the beginning of a pipe sequence inside a function – I can only think of creating side effects and relying on [R’s implicit return of the last evaluated expression](https://rdrr.io/r/base/function.html). Therefore – and because I really like the `%<>%` operator – it’s usage is welcome.

Expand Down
78 changes: 25 additions & 53 deletions docs/dev/LICENSE.html

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

Loading

0 comments on commit 21edf83

Please sign in to comment.