-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add use_memoise() helper to change behavior on the fly (x
fixes #71 and #77 --------- Co-authored-by: Hugo Gruson <[email protected]> Co-authored-by: Matthias Grenié <[email protected]>
- Loading branch information
1 parent
d11d749
commit cc35fc4
Showing
27 changed files
with
446 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
paths: | ||
- README.Rmd | ||
|
||
name: Render README | ||
|
||
jobs: | ||
render-rmarkdown: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: r-lib/actions/setup-pandoc@v2 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
|
||
- uses: r-lib/actions/setup-renv@v2 | ||
|
||
- name: Render Rmarkdown files and Commit Results | ||
run: | | ||
RMD_PATH=($(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '[.]Rmd$')) | ||
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f)' ${RMD_PATH[*]} | ||
git config --local user.name "$GITHUB_ACTOR" | ||
git config --local user.email "[email protected]" | ||
git commit ${RMD_PATH[*]/.Rmd/.md} -m 'Re-build Rmarkdown files' || echo "No changes to commit" | ||
git push origin || echo "No changes to commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' Options for \pkg{fundiversity} | ||
#' | ||
#' The memoisation is the convex hull computation in \pkg{fundiversity} is | ||
#' controlled via the `fundiversity.memoise` option: | ||
#' - if unset, the default is to use memoisation if \pkg{memoise} was installed | ||
#' when \pkg{fundiversity} was loaded, and not to use memoisation otherwise. | ||
#' - if `options(fundiversity.memoise = TRUE)`, memoisation is used and an error | ||
#' is thrown if \pkg{memoise} is not installed. | ||
#' - if `options(fundiversity.memoise = FALSE)`, memoisation is not used. | ||
#' | ||
#' @name fundiversity-options | ||
NULL | ||
|
||
#' @keywords internal | ||
use_memoise <- function() { | ||
|
||
# Cannot use memoise in parallel settings | ||
if (!inherits(future::plan(), "sequential")) { | ||
return(FALSE) | ||
} | ||
|
||
# explicitly set to TRUE by user | ||
if (isTRUE(getOption("fundiversity.memoise"))) { | ||
if (exists("fd_chull_memoised")) { | ||
return(TRUE) | ||
} | ||
stop( | ||
"memoise is not installed ", | ||
"or was installed after fundiversity was loaded. ", | ||
"Please install memoise and restart R.", | ||
call. = FALSE | ||
) | ||
} | ||
# explicitly set to FALSE by user | ||
if (isFALSE(getOption("fundiversity.memoise"))) { | ||
return(FALSE) | ||
} | ||
# unspecified / default | ||
# TRUE or FALSE depending on whether memoise was installed when fundiversity | ||
# was loaded | ||
return(exists("fd_chull_memoised")) | ||
} | ||
|
||
# Added this to make 'testthat::local_mocked_bindings()' work | ||
# in 'test-use_memoise.R' | ||
exists <- NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
# Diverse utility functions | ||
|
||
# Memoized version of fd_chull loaded if package is installed | ||
.onLoad <- function(libname, pkgname) { | ||
if (requireNamespace("memoise", quietly = TRUE) && | ||
isTRUE(getOption("fundiversity.memoise", TRUE))) { | ||
fd_chull <<- memoise::memoise(fd_chull) | ||
fd_chull_intersect <<- memoise::memoise(fd_chull_intersect) | ||
if (requireNamespace("memoise", quietly = TRUE)) { | ||
fd_chull_memoised <<- memoise::memoise(fd_chull) | ||
fd_chull_intersect_memoised <<- memoise::memoise(fd_chull_intersect) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.