Skip to content

Commit

Permalink
resolve cache issues #4
Browse files Browse the repository at this point in the history
added donttest to all function examples
default to cache = TRUE if not interactive
clear the cache after tests if not interactive
  • Loading branch information
japhir committed May 18, 2023
1 parent c66f727 commit b0c2231
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
* Added a vignette with a grid of variations on Td and Ed.
* Added a bookdown website rendering.
* Released a version to Zenodo and assigned a doi.
* Added the caching code to the .onLoad call in zzz.R
* Added functions get_solution, get_ZB18a, prepare_solution
* Removed `ZB18a` dataset from the package because it was too large.
* Added functions get_solution, get_ZB18a, prepare_solution.
* Added caching code for the orbital solution.
* Remove the cache directory after running tests, so that reproducible environments remain clean.
8 changes: 6 additions & 2 deletions R/get_solution.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#' @returns `get_solution()` returns a [tibble][tibble::tibble-package] with the
#' orbital solution input and some preprocessed new columns.
#' @examples
#' \donttest{
#' get_solution()
#' }
#' @export
get_solution <- function(orbital_solution = "ZB18a", quiet = FALSE) {
solutions <- c("ZB18a", "La11")
Expand Down Expand Up @@ -49,7 +51,9 @@ get_solution <- function(orbital_solution = "ZB18a", quiet = FALSE) {
#' @seealso [prepare_solution()] Processes orbital solution input to include
#' helper columns.
#' @examples
#' \donttest{
#' get_ZB18a()
#' }
#' @export
get_ZB18a <- function(quiet = FALSE, force = FALSE) {
ZB18a_url <- "http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/PrecTilt/OS/ZB18a/ems-plan3.dat"
Expand All @@ -67,8 +71,8 @@ get_ZB18a <- function(quiet = FALSE, force = FALSE) {
# default to Yes downloading if not interactive (i.e. GitHub actions)
if (!interactive()) {
download <- TRUE
# default to no caching, so that we're not writing to the user's directory
save_cache <- FALSE
# default to cache
save_cache <- TRUE
} else {# we're interactive
# a logical, TRUE if Yes, no if otherwise
download <- utils::menu(c("Yes", "No"), title = "Would you like to download and process it now?") == 1L
Expand Down
3 changes: 2 additions & 1 deletion R/snvec.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@
#'
#' @examples
#' # default call
#' \donttest{
#' snvec()
#'
#' }
#' @export
snvec <- function(tend = -1e3,
ed = 1,
Expand Down
2 changes: 2 additions & 0 deletions man/ZB18a.Rd

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

2 changes: 2 additions & 0 deletions man/get_solution.Rd

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

3 changes: 2 additions & 1 deletion man/snvec.Rd

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

7 changes: 7 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ library(testthat)
library(snvecR)

test_check("snvecR")

# clean up after tests
cachedir <- tools::R_user_dir("snvecR", which = "cache")
if (dir.exists(cachedir)) {
cli::cli_inform("Removing {.file {cachedir}} from reproducible environment.")
unlink(cachedir, recursive = TRUE)
}

0 comments on commit b0c2231

Please sign in to comment.