diff --git a/.Rbuildignore b/.Rbuildignore index c37dd751..2a1ab9c8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,4 +12,6 @@ ^paper$ ^.Renviron$ ^_pkgdown\.yml$ +^pkgdown$ ^\.github$ +^man/figures/portalr.png$ diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/R-CMD-check.yaml similarity index 55% rename from .github/workflows/check-standard.yaml rename to .github/workflows/R-CMD-check.yaml index 8b013a45..d7fb3eb4 100644 --- a/.github/workflows/check-standard.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,16 +1,14 @@ -# R package checking # 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: - branches: - - main + branches: [main] pull_request: - branches: - - main - workflow_dispatch: + branches: [main] + +name: R-CMD-check.yaml -name: R-CMD-check +permissions: read-all jobs: R-CMD-check: @@ -22,16 +20,17 @@ jobs: fail-fast: false matrix: config: - - {os: windows-latest, r: 'release'} - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -41,14 +40,12 @@ jobs: http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - name: Install Dependencies - uses: r-lib/actions/setup-r-dependencies@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::rcmdcheck needs: check - - name: R CMD check - uses: r-lib/actions/check-r-package@v2 + - uses: r-lib/actions/check-r-package@v2 with: - error-on: '"error"' upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 040c17b2..c0c5ed32 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,38 +1,50 @@ -# building website - +# 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: - branches: - - main + branches: [main] + pull_request: + branches: [main] release: types: [published] + workflow_dispatch: + +name: pkgdown.yaml -name: pkgdown +permissions: read-all jobs: pkgdown: runs-on: ubuntu-latest - + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v2 - - - name: Install Dependencies - uses: r-lib/actions/setup-r-dependencies@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::pkgdown, local::. needs: website - - name: Deploy package - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, examples = FALSE)' + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 00000000..a32f8624 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,61 @@ +# 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: + branches: [main] + pull_request: + branches: [main] + +name: test-coverage.yaml + +permissions: read-all + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr, any::xml2 + needs: coverage + + - name: Test coverage + run: | + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + covr::to_cobertura(cov) + shell: Rscript {0} + + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml deleted file mode 100644 index 1fa64d65..00000000 --- a/.github/workflows/test-coverage.yml +++ /dev/null @@ -1,34 +0,0 @@ -on: - push: - branches: - - main - pull_request: - branches: - - main - -name: test-coverage - -jobs: - test-coverage: - runs-on: ubuntu-latest - - env: - R_DEFAULT_INTERNET_TIMEOUT: 300 - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v3 - - - uses: r-lib/actions/setup-r@v2 - - - uses: r-lib/actions/setup-pandoc@v2 - - - name: Install Dependencies - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::covr - needs: coverage - - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} diff --git a/.gitignore b/.gitignore index c8fb339f..d7018886 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ doc # produced vignettes vignettes/*.html vignettes/*.pdf -# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +# OAuth2 token, see https://github.com/r-lib/httr/releases/tag/v0.3 .httr-oauth # knitr and R markdown default cache directories /*_cache/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee5a2aff..4b53fbbc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,4 +65,4 @@ The suggested workflow is: If you are also prepping the package as a whole, then you will also want to run `devtools::check()` and/or `devtools::check_cran()` to make sure that the package is complete. -For more info, see the [GitHub repo](https://github.com/hadley/devtools) for the `devtools` package. +For more info, see the [GitHub repo](https://github.com/r-lib/devtools) for the `devtools` package. diff --git a/DESCRIPTION b/DESCRIPTION index d22bc77f..a88abe9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,9 +53,8 @@ BugReports: https://github.com/weecology/portalr/issues Depends: R (>= 3.2.3) Imports: - clipr, - clisymbols, - crayon, + cli, + clipr, dplyr, forecast, httr, @@ -64,18 +63,17 @@ Imports: magrittr, rlang, tidyr, - tidyselect (>= 1.0.0), + tidyselect (>= 1.2.1), zoo Suggests: - covr, cowplot, ggplot2, httptest, knitr, - pkgdown, rmarkdown, - testthat + testthat (>= 3.0.0) VignetteBuilder: knitr Encoding: UTF-8 RoxygenNote: 7.3.1 +Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index 63514751..3beed195 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,15 @@ # portalr +* `portalr` now uses [testthat 3rd edition](https://testthat.r-lib.org/articles/third-edition.html) +* `portalr` no longer imports clisymbols and crayon. Its messages are gemerated with cli. +* `format_todo()`, `format_code()`, and `format_value()` can be replaced with + [inline markup](https://cli.r-lib.org/articles/usethis-ui.html) (i.e. `{.val}`, `{.code}`, etc.) and + may be removed from the package. + Version numbers follow [Semantic Versioning](https://semver.org/). # [portalr 0.4.1](https://github.com/weecology/portalr/releases/tag/v0.4.1) -*2023-08-223* +*2023-08-23* ### Regional weather filling includes more stations @@ -20,6 +26,6 @@ Version numbers follow [Semantic Versioning](https://semver.org/). * now defaulty for number of moons to add is `NULL` and there is a call to `return_if_null` on it ### addition of new functions (pulled from portalcasting) -* `return_if_null` -* `rodent_species`: helper function that now operates off of the rodent table, not hard-coded -* `na_conformer`: makes sure the species abbreviation for Neotoma albigula is a character value +* `return_if_null()` +* `rodent_species()`: helper function that now operates off of the rodent table, not hard-coded +* `na_conformer()`: makes sure the species abbreviation for Neotoma albigula is a character value diff --git a/R/download_data.R b/R/download_data.R index dd47d6ec..ecfc89e8 100644 --- a/R/download_data.R +++ b/R/download_data.R @@ -35,6 +35,7 @@ download_observations <- function (path = get_default_data_path(), force = FALSE) { return_if_null(x = version) + latest_requested <- identical(version, "latest") timeout_backup <- getOption("timeout") on.exit(options(timeout = timeout_backup)) @@ -113,8 +114,10 @@ download_observations <- function (path = get_default_data_path(), if (existing_version == version) { - if (!quiet) { - message("Existing local version is up-to-date with remote version (", version, ") requested and `force` is FALSE, download is skipped") + # Avoid showing message in test (except if latest version is requested) + # use rlang::local_interactive() to simulate this message in non-interactive session. + if (!quiet && (rlang::is_interactive() || latest_requested)) { + message("Existing local version is up-to-date with remote version (", version, ") requested and `force` is FALSE, download is skipped") } return(invisible()) @@ -122,8 +125,9 @@ download_observations <- function (path = get_default_data_path(), } } - - if (!quiet) { + # Avoid showing message in test (inform of version if latest is requested) + # use rlang::local_interactive() to simulate this message in non-interactive session. + if (!quiet && (rlang::is_interactive() || latest_requested)) { message("Downloading version `", version, "` of the data...") } @@ -246,12 +250,14 @@ check_default_data_path <- function(ENV_VAR = "PORTALR_DATA_PATH", { if (is.na(get_default_data_path(fallback = NA, ENV_VAR))) { - MESSAGE_FUN("You don't appear to have a defined location for storing ", DATA_NAME, ".") - MESSAGE_FUN(format_todo(" Call ", - format_code('use_default_data_path(\"\")'), - " if you wish to set the default data path.")) - MESSAGE_FUN(DATA_NAME, " will be downloaded into ", - format_code(path.expand("~")), " otherwise.") + msg <- cli::format_message( + c( + "You don't appear to have a defined location for storing {DATA_NAME}.", + "i" = "Call {.code use_default_data_path(\"path\")} if you wish to set the default data path.", + "i" = "{DATA_NAME} will be downloaded into {.path {path.expand('~')}} otherwise." + ) + ) + MESSAGE_FUN(msg) return(FALSE) } return(TRUE) @@ -311,14 +317,17 @@ use_default_data_path <- function(path = NULL, ENV_VAR = "PORTALR_DATA_PATH") # display message and copy new path setting to clipboard path_setting_string <- paste0(ENV_VAR, "=", '"', path, '"') - message(format_todo("Call ", format_code('usethis::edit_r_environ()'), " to open ", - format_value('.Renviron'))) - message(format_todo("Store your data path with a line like:")) - message(" ", format_code(path_setting_string)) + cli::cli_inform(c( + "*" = "Call {.run usethis::edit_r_environ()} to open {.val .Renviron}.", + "*" = "Store your data path with a line like:", + " " = path_setting_string + )) if (rlang::is_interactive() && clipr::clipr_available()) { clipr::write_clip(path_setting_string) - message(" [Copied to clipboard]") + cli::cli_inform(" [Copied to clipboard]") } - message(format_todo("Make sure ", format_value('.Renviron'), " ends with a newline!")) + cli::cli_inform(c( + "*" = "Make sure {.val .Renviron} ends with a newline!" + )) return() } diff --git a/R/load_data.R b/R/load_data.R index 76adcb49..13bc7eaf 100644 --- a/R/load_data.R +++ b/R/load_data.R @@ -219,7 +219,8 @@ load_datafile <- function(datafile, na.strings = "", path = get_default_data_pat } ## output message about data version - if (!quiet) + # Silence this message in testing. + if (!quiet && !identical(Sys.getenv("TESTTHAT"), "true")) { version_file <- file.path(base_path, "version.txt") if (tolower(path) != "repo" && !file.exists(version_file)) diff --git a/R/process_data_utils.R b/R/process_data_utils.R index 65482e67..f6684b80 100644 --- a/R/process_data_utils.R +++ b/R/process_data_utils.R @@ -14,7 +14,7 @@ clean_data <- function(full_data, trapping_table, ...) { full_data <- full_data %>% dplyr::left_join(trapping_table, ...) %>% dplyr::filter(.data$qcflag == 1) %>% - dplyr::select(columns_to_keep) %>% + dplyr::select(dplyr::all_of(columns_to_keep)) %>% unique() return(full_data) diff --git a/R/utils-format-message.R b/R/utils-format-message.R index 65ff6c83..0e83aa1c 100644 --- a/R/utils-format-message.R +++ b/R/utils-format-message.R @@ -8,7 +8,7 @@ format_value <- function(...) { x <- paste0(..., collapse = "") x <- encodeString(x, quote = "'") - crayon::blue(x) + cli::col_blue(x) } #' Format content as an action to be performed by the user @@ -19,7 +19,7 @@ format_value <- function(...) #' @export format_todo <- function(...) { - paste0(crayon::red(clisymbols::symbol$bullet), " ", ..., collapse = "") + paste0(cli::col_red(cli::symbol$bullet), " ", ..., collapse = "") } #' Format content as code @@ -32,5 +32,5 @@ format_code <- function(...) { x <- paste0(..., collapse = "") x <- encodeString(x, quote = "`") - crayon::silver(x) + cli::col_silver(x) } diff --git a/R/zzz.R b/R/zzz.R index 55891a92..17d8194e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,10 +3,13 @@ check_default_data_path(MESSAGE_FUN = packageStartupMessage) && check_for_newer_data()) { - packageStartupMessage("The data in the default path `", - normalizePath(get_default_data_path()), - "` is either missing or out of date.\n", - "Consider updating it using `download_observations()`.") + default_path <- normalizePath(get_default_data_path()) + msg <- cli::format_message(c( + "The data in the default path {.path {default_path}} is \\ + either missing or out of date.", + i = "Consider updating it using `download_observations()`." + )) + packageStartupMessage(msg) } invisible() } diff --git a/README.Rmd b/README.Rmd index 78477003..16cc308c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -14,12 +14,12 @@ knitr::opts_chunk$set( library(portalr) ``` -# portalr +# portalr -[![R-CMD-check](https://github.com/weecology/portalr/workflows/R-CMD-check/badge.svg)](https://github.com/weecology/portalr/actions) +[![R-CMD-check](https://github.com/weecology/portalr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/weecology/portalr/actions/workflows/R-CMD-check.yaml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/weecology/portalr/main/LICENSE) -[![Coverage status](https://codecov.io/gh/weecology/portalr/branch/main/graph/badge.svg)](https://app.codecov.io/github/weecology/portalr?branch=main) +[![Codecov test coverage](https://codecov.io/gh/weecology/portalr/graph/badge.svg)](https://app.codecov.io/gh/weecology/portalr) [![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/portalr)](https://CRAN.R-project.org/package=portalr) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1429290.svg)](https://doi.org/10.5281/zenodo.1429290) @@ -27,8 +27,6 @@ library(portalr) [![NSF-1929730](https://img.shields.io/badge/NSF-1929730-blue.svg)](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1929730) - - ## Overview The **portalr** package provides collection of basic functions to summarize the Portal project data on rodents, plants, ants, and weather at our long-term field site in the Chihuahuan Desert. The data begin in 1977 and are continuously updated today. There are functions to summarize rodent abundance, biomass, or energy and by site, plot, or treatment type. There are functions to summarize the weather data collected from our automated weather stations and plant data that is collected each summer and fall. diff --git a/README.md b/README.md index 836c73b4..d5e06236 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ -# portalr +# portalr -[![R-CMD-check](https://github.com/weecology/portalr/workflows/R-CMD-check/badge.svg)](https://github.com/weecology/portalr/actions) +[![R-CMD-check](https://github.com/weecology/portalr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/weecology/portalr/actions/workflows/R-CMD-check.yaml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/weecology/portalr/main/LICENSE) -[![Coverage -status](https://codecov.io/gh/weecology/portalr/branch/main/graph/badge.svg)](https://app.codecov.io/github/weecology/portalr?branch=main) +[![Codecov test +coverage](https://codecov.io/gh/weecology/portalr/graph/badge.svg)](https://app.codecov.io/gh/weecology/portalr) + [![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/portalr)](https://CRAN.R-project.org/package=portalr) @@ -17,8 +18,6 @@ downloads](https://cranlogs.r-pkg.org/badges/grand-total/portalr)](https://CRAN. [![NSF-1929730](https://img.shields.io/badge/NSF-1929730-blue.svg)](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1929730) - - ## Overview The **portalr** package provides collection of basic functions to @@ -118,6 +117,7 @@ To cite the Portal dataset, use: ``` r get_dataset_citation() +#> #> To cite the Portal Data in publications, use: #> #> S. K. Morgan Ernest, Glenda M. Yenni, Ginger Allington, Ellen K. diff --git a/_pkgdown.yml b/_pkgdown.yml index 1db690e4..2cb093f9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,8 @@ url: https://weecology.github.io/portalr + +template: + bootstrap: 5 + development: mode: auto reference: @@ -46,4 +50,4 @@ reference: - return_if_null - rodent_species - portalr - + diff --git a/man/figures/logo.png b/man/figures/logo.png new file mode 100644 index 00000000..855356c2 Binary files /dev/null and b/man/figures/logo.png differ diff --git a/man/load_datafile.Rd b/man/load_datafile.Rd index fcae1c94..f3186816 100644 --- a/man/load_datafile.Rd +++ b/man/load_datafile.Rd @@ -18,8 +18,8 @@ load_datafile( \item{na.strings}{a character vector of strings which are to be interpreted as \code{\link{NA}} values. Blank fields are also considered to be missing values in logical, integer, numeric and - complex fields. Note that the test happens \emph{after} - white space is stripped from the input, so \code{na.strings} + complex fields. Note that the test happens \emph{after} + white space is stripped from the input, so \code{na.strings} values may need their own white space stripped in advance.} \item{path}{either the file path that contains the PortalData folder or diff --git a/pkgdown/favicon/apple-touch-icon-120x120.png b/pkgdown/favicon/apple-touch-icon-120x120.png new file mode 100644 index 00000000..4beaaf07 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-120x120.png differ diff --git a/pkgdown/favicon/apple-touch-icon-152x152.png b/pkgdown/favicon/apple-touch-icon-152x152.png new file mode 100644 index 00000000..1598066b Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-152x152.png differ diff --git a/pkgdown/favicon/apple-touch-icon-180x180.png b/pkgdown/favicon/apple-touch-icon-180x180.png new file mode 100644 index 00000000..c833023b Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-180x180.png differ diff --git a/pkgdown/favicon/apple-touch-icon-60x60.png b/pkgdown/favicon/apple-touch-icon-60x60.png new file mode 100644 index 00000000..885e1519 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-60x60.png differ diff --git a/pkgdown/favicon/apple-touch-icon-76x76.png b/pkgdown/favicon/apple-touch-icon-76x76.png new file mode 100644 index 00000000..607cf55a Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-76x76.png differ diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png new file mode 100644 index 00000000..a7dbff35 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-16x16.png b/pkgdown/favicon/favicon-16x16.png new file mode 100644 index 00000000..664bc2e1 Binary files /dev/null and b/pkgdown/favicon/favicon-16x16.png differ diff --git a/pkgdown/favicon/favicon-32x32.png b/pkgdown/favicon/favicon-32x32.png new file mode 100644 index 00000000..f866825d Binary files /dev/null and b/pkgdown/favicon/favicon-32x32.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico new file mode 100644 index 00000000..206c2d46 Binary files /dev/null and b/pkgdown/favicon/favicon.ico differ diff --git a/tests/testthat.R b/tests/testthat.R index 81ae25f6..b1b048ef 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(portalr) diff --git a/tests/testthat/_snaps/01-data-retrieval.md b/tests/testthat/_snaps/01-data-retrieval.md new file mode 100644 index 00000000..b057a7d0 --- /dev/null +++ b/tests/testthat/_snaps/01-data-retrieval.md @@ -0,0 +1,23 @@ +# default data path functions work if unset + + Code + check_default_data_path() + Message + You don't appear to have a defined location for storing Portal data. + i Call `use_default_data_path("path")` if you wish to set the default data path. + i Portal data will be downloaded into '' otherwise. + Output + [1] FALSE + +--- + + Code + use_default_data_path(data_path) + Message + * Call `usethis::edit_r_environ()` to open ".Renviron". + * Store your data path with a line like: + PORTALR_DATA_PATH="" + * Make sure ".Renviron" ends with a newline! + Output + NULL + diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R deleted file mode 100644 index f0f90c78..00000000 --- a/tests/testthat/setup.R +++ /dev/null @@ -1,5 +0,0 @@ -pre_test_options <- options( - ## make ui_*() output easier to test against - ## just say no to ANSI escape codes - "crayon.enabled" = FALSE -) diff --git a/tests/testthat/teardown.R b/tests/testthat/teardown.R deleted file mode 100644 index 6c7ef9f2..00000000 --- a/tests/testthat/teardown.R +++ /dev/null @@ -1 +0,0 @@ -options(pre_test_options) diff --git a/tests/testthat/test-01-data-retrieval.R b/tests/testthat/test-01-data-retrieval.R index 7aabc55e..272b4c8f 100644 --- a/tests/testthat/test-01-data-retrieval.R +++ b/tests/testthat/test-01-data-retrieval.R @@ -1,23 +1,23 @@ -context("Check data retrieval") - +# Check data retrieval portal_data_path <- tempdir() test_that("download_observations and check_for_newer_data work", { skip_on_cran() # these download checks take a while to run - expect_error(download_observations(portal_data_path, version = "1.20.0"), NA) + skip_if_not_installed("httptest") + expect_no_error(download_observations(portal_data_path, version = "1.20.0")) expect_true(check_for_newer_data(portal_data_path)) httptest::without_internet({ expect_false(check_for_newer_data(portal_data_path)) }) unlink(file.path(portal_data_path, "PortalData"), recursive = TRUE) + # Expect a message if requesting latest data expect_message(download_observations(portal_data_path)) + # Expecting a message that latest data is already available expect_message(download_observations(portal_data_path)) unlink(file.path(portal_data_path, "PortalData"), recursive = TRUE) - - - expect_error(download_observations(portal_data_path, version = "1.6.0"), NA) + expect_no_error(download_observations(portal_data_path, version = "1.6.0")) expect_true(check_for_newer_data(portal_data_path)) unlink(file.path(portal_data_path, "PortalData"), recursive = TRUE) expect_true(check_for_newer_data(portal_data_path)) @@ -25,12 +25,14 @@ test_that("download_observations and check_for_newer_data work", { expect_error(download_observations(portal_data_path, version = "1.5.9")) expect_error(download_observations(portal_data_path, version = "1.000.0")) - expect_error(download_observations(portal_data_path, source = "zenodo", timeout = 300), NA) + # Error here + # do not know how to convert 'pub_date' to class "Date" + expect_no_error(download_observations(portal_data_path, source = "zenodo", timeout = 300)) expect_error(download_observations(portal_data_path, source = "xxx"), "`source` must be either 'zenodo' or 'github'") expect_false(check_for_newer_data(portal_data_path)) #unlink(file.path(portal_data_path, "PortalData"), recursive = TRUE) - expect_error(download_observations(portal_data_path), NA) + expect_no_error(download_observations(portal_data_path)) expect_false(check_for_newer_data(portal_data_path)) unlink(file.path(portal_data_path, "PortalData"), recursive = TRUE) }) @@ -44,28 +46,28 @@ test_that("load_rodent_data downloads data if missing", { test_that("load_rodent_data has the right format", { skip_on_cran() - expect_error(data_tables <- load_rodent_data("repo"), NA) - expect_equal(length(data_tables), 5) - expect_equal(names(data_tables), + expect_no_error(data_tables <- load_rodent_data("repo")) + expect_length(data_tables, 5) + expect_named(data_tables, c("rodent_data", "species_table", "trapping_table", "newmoons_table", "plots_table")) data_tables <- load_rodent_data(portal_data_path) - expect_equal(length(data_tables), 5) - expect_equal(names(data_tables), + expect_length(data_tables, 5) + expect_named(data_tables, c("rodent_data", "species_table", "trapping_table", "newmoons_table", "plots_table")) }) test_that("load_plant_data has the right format", { skip_on_cran() - expect_error(data_tables <- load_plant_data("repo"), NA) - expect_equal(length(data_tables), 7) - expect_equal(names(data_tables), + expect_no_error(data_tables <- load_plant_data("repo")) + expect_length(data_tables, 7) + expect_named(data_tables, c("quadrat_data", "species_table", "census_table", "date_table", "plots_table", "transect_data", "oldtransect_data")) - expect_error(data_tables <- load_plant_data(portal_data_path), NA) + expect_no_error(data_tables <- load_plant_data(portal_data_path)) expect_equal(length(data_tables), 7) expect_equal(names(data_tables), c("quadrat_data", "species_table", "census_table", @@ -74,15 +76,15 @@ test_that("load_plant_data has the right format", { test_that("load_ant_data works", { skip_on_cran() - expect_error(data_tables <- load_ant_data("repo"), NA) - expect_equal(length(data_tables), 4) - expect_equal(names(data_tables), + expect_no_error(data_tables <- load_ant_data("repo")) + expect_length(data_tables, 4) + expect_named(data_tables, c("bait_data", "colony_data", "species_table", "plots_table")) - expect_error(data_tables <- load_ant_data(portal_data_path), NA) - expect_equal(length(data_tables), 4) - expect_equal(names(data_tables), + expect_no_error(data_tables <- load_ant_data(portal_data_path)) + expect_length(data_tables, 4) + expect_named(data_tables, c("bait_data", "colony_data", "species_table", "plots_table")) }) @@ -93,19 +95,24 @@ test_that("default data path functions work if unset", { "You don't appear to have a defined location for storing Portal data.") expect_false(result) - m <- capture_messages(check_default_data_path()) - expect_match(m, "You don't appear to have a defined location for storing Portal data.", all = FALSE) - expect_match(m, "Call .+ if you wish to set the default data path.", all = FALSE) - expect_match(m, "Portal data will be downloaded into .+ otherwise.", all = FALSE) + # Use snapshot to test for no error + message + expect_snapshot( + check_default_data_path(), + # transform user path (in case cli uses double quotes on path one day) + # If check_default_data_path message changes, the regex here will need to be adjusted + transform = function(x) sub("into ['\"].+['\"]", "into ''", x) + ) expect_error(use_default_data_path()) data_path <- tempdir() - expect_error(m <- capture_messages(use_default_data_path(data_path)), NA) - expect_match(m, "Call `usethis::edit_r_environ()` to open '.Renviron'", fixed = TRUE, all = FALSE) - expect_match(m, "Store your data path with a line like:", all = FALSE) - expect_match(m, "PORTALR_DATA_PATH=", all = FALSE) - expect_match(m, "Make sure '.Renviron' ends with a newline!", all = FALSE) + # Use snapshot to test for no error + message + expect_snapshot( + use_default_data_path(data_path), + # avoid showing temp path in snapshot + # If use_default_data_path message changes, the regex here will need to be adjusted + transform = function(x) sub("=\".+\"", "=\"\"", x) + ) }) test_that("default data path functions work if set", { diff --git a/tests/testthat/test-02-data-processing.R b/tests/testthat/test-02-data-processing.R index 4a049d4e..af17c056 100644 --- a/tests/testthat/test-02-data-processing.R +++ b/tests/testthat/test-02-data-processing.R @@ -1,4 +1,4 @@ -context("Check data processing") +# Check data processing eps <- if (capabilities("long.double")) sqrt(.Machine$double.eps) else @@ -44,9 +44,9 @@ test_that("clean_rodent_data has correct columns", { expect_true("wgt" %in% rodent_cols) expect_true("energy" %in% rodent_cols) - expect_is(rodents$species, "factor") - expect_is(rodents$wgt, "numeric") - expect_is(rodents$energy, "numeric") + expect_s3_class(rodents$species, "factor") + expect_type(rodents$wgt, "double") + expect_type(rodents$energy, "double") expect_equal(is.na(rodents$wgt), is.na(rodents$energy), tolerance = eps) expect_equal(5.69 * rodents$wgt[!is.na(rodents$wgt)] ^ 0.75, rodents$energy[!is.na(rodents$energy)], tolerance = eps) @@ -82,10 +82,10 @@ test_that("does filter_plots work properly?", { test_that("does find_incomplete_censuses work properly?", { trappings <- data_tables$trapping_table - expect_error(fewer_than_24_plots <- find_incomplete_censuses(trappings, 24, 1), NA) + expect_no_error(fewer_than_24_plots <- find_incomplete_censuses(trappings, 24, 1)) expect_equal(dim(dplyr::filter(fewer_than_24_plots, period < 100)), c(27, 1)) - expect_error(any_incomplete <- find_incomplete_censuses(trappings, 24, 49), NA) - expect_error(missing_traps <- find_incomplete_censuses(trappings, 24, 47), NA) + expect_no_error(any_incomplete <- find_incomplete_censuses(trappings, 24, 49)) + expect_no_error(missing_traps <- find_incomplete_censuses(trappings, 24, 47)) expect_gt(NROW(any_incomplete), NROW(missing_traps)) periods_47_traps <- setdiff(any_incomplete$period, missing_traps$period) idx <- periods_47_traps > 320 & periods_47_traps < 450 @@ -117,7 +117,7 @@ test_that("species data.frame has correct column names", { }) test_that("clean_plant_data works", { - expect_error(plants <- clean_plant_data(plant_tables), NA) + expect_no_error(plants <- clean_plant_data(plant_tables)) }) plants <- clean_plant_data(plant_tables) @@ -135,7 +135,7 @@ test_that("clean_plant_data has correct columns", { expect_true('duration' %in% plant_cols) expect_true('community' %in% plant_cols) - expect_is(plants$species, "factor") - expect_is(plants$abundance, "integer") - expect_is(plants$cover, "numeric") + expect_s3_class(plants$species, "factor") + expect_type(plants$abundance, "integer") + expect_type(plants$cover, "double") }) diff --git a/tests/testthat/test-03-summarize-rodents.R b/tests/testthat/test-03-summarize-rodents.R index 910e3453..9fc1546f 100644 --- a/tests/testthat/test-03-summarize-rodents.R +++ b/tests/testthat/test-03-summarize-rodents.R @@ -1,4 +1,4 @@ -context("Check rodent data summaries") +# Check rodent data summaries portal_data_path <- tempdir() @@ -195,44 +195,44 @@ test_that("rodent_species provides proper vectors or data frame", { skip_on_cran() rodents <- rodent_species() - expect_equal(length(rodents), 30) + expect_length(rodents, 30) all_rodents <- rodent_species(set = "all") - expect_equal(length(all_rodents), 30) + expect_length(all_rodents, 30) fc_rodents <- rodent_species(set = "forecasting") - expect_equal(length(fc_rodents), 20) + expect_length(fc_rodents, 20) fct_rodents <- rodent_species(set = "forecasting", total = TRUE) - expect_equal(length(fct_rodents), 21) + expect_length(fct_rodents, 21) - expect_is(rodents, "character") - expect_is(all_rodents, "character") - expect_is(fc_rodents, "character") - expect_is(fct_rodents, "character") + expect_type(rodents, "character") + expect_type(all_rodents, "character") + expect_type(fc_rodents, "character") + expect_type(fct_rodents, "character") rodent_abbr <- rodent_species(type = "abbreviation") - expect_is(rodent_abbr, "character") + expect_type(rodent_abbr, "character") expect_equal(unique(nchar(rodent_abbr)), 2) rodent_comm <- rodent_species(type = "common") - expect_is(rodent_comm , "character") + expect_type(rodent_comm , "character") expect_equal(unique(nchar(rodent_comm)), c(26, 20, 21, 19, 17, 31, 22, 18, 12, 10, 13, 24, 23, 28)) rodent_scie <- rodent_species(type = "scientific") - expect_is(rodent_scie, "character") + expect_type(rodent_scie, "character") expect_equal(unique(nchar(rodent_scie)), c(24, 15, 19, 20, 23, 26, 18, 13, 21, 16, 22, 25, 10, 17, 12, 29)) rodent_gs <- rodent_species(type = "g_species") - expect_is(rodent_gs, "character") + expect_type(rodent_gs, "character") expect_equal(unique(nchar(rodent_gs)), c(10, 11, 14, 15, 6, 8, 9, 13, 12)) rodent_t <- rodent_species(type = "table") - expect_is(rodent_t, "data.frame") + expect_s3_class(rodent_t, "data.frame") expect_equal(dim(rodent_t), c(30, 4)) rodent_tt <- rodent_species(type = "table", total = TRUE) - expect_is(rodent_tt, "data.frame") + expect_s3_class(rodent_tt, "data.frame") expect_equal(dim(rodent_tt), c(31, 4)) expect_error(rodent_species(type = "error")) @@ -243,8 +243,7 @@ test_that("rodent_species provides proper vectors or data frame", { -test_that(desc = "na_conformer makes NA into `NA` in vectors and data frames", - code = { +test_that("na_conformer makes NA into `NA` in vectors and data frames", { # work on vectors @@ -254,7 +253,7 @@ test_that(desc = "na_conformer makes NA into `NA` in vectors and data frames", # works on dfs xx <- data.frame(w = "a", n = as.character(c("d", NA, "a", "b", "c"))) - expect_is(na_conformer(xx, "n"), "data.frame") + expect_s3_class(na_conformer(xx, "n"), "data.frame") expect_equal(na_conformer(xx, "n")[2,2], "NA") }) diff --git a/tests/testthat/test-04-weather.R b/tests/testthat/test-04-weather.R index 220ea4a5..93f697b3 100644 --- a/tests/testthat/test-04-weather.R +++ b/tests/testthat/test-04-weather.R @@ -1,4 +1,4 @@ -context("checks weather summary output") +# checks weather summary output portal_data_path <- tempdir() daily_weather <- weather("daily", path = portal_data_path) @@ -6,17 +6,17 @@ monthly_weather <- weather("monthly", path = portal_data_path) newmoon_weather <- weather("newmoon", path = portal_data_path) test_that("'Daily' option returns 13 columns", { - expect_that(dim(daily_weather)[2], equals(13)) - expect_equal(colnames(daily_weather), + expect_equal(dim(daily_weather)[2], 13) + expect_named(daily_weather, c("date", "year", "month", "day", "mintemp", "maxtemp", "meantemp", "precipitation", "locally_measured", "battery_low", "warm_days", "cool_precip", "warm_precip")) }) test_that("Daily temperatures ok", { - expect_equal(length(which((daily_weather$mintemp <= daily_weather$maxtemp) == FALSE)),0) - expect_equal(length(which((daily_weather$meantemp <= daily_weather$maxtemp) == FALSE)),0) - expect_equal(length(which((daily_weather$mintemp <= daily_weather$meantemp) == FALSE)),0) + expect_length(which((daily_weather$mintemp <= daily_weather$maxtemp) == FALSE), 0) + expect_length(which((daily_weather$meantemp <= daily_weather$maxtemp) == FALSE), 0) + expect_length(which((daily_weather$mintemp <= daily_weather$meantemp) == FALSE), 0) }) test_that("Monthly option returns 11 columns", { @@ -29,9 +29,9 @@ test_that("Monthly option returns 11 columns", { }) test_that("Monthly temperatures ok", { - expect_equal(length(which((monthly_weather$mintemp <= monthly_weather$maxtemp) == FALSE)),0) - expect_equal(length(which((monthly_weather$meantemp <= monthly_weather$maxtemp) == FALSE)),0) - expect_equal(length(which((monthly_weather$mintemp <= monthly_weather$meantemp) == FALSE)),0) + expect_length(which((monthly_weather$mintemp <= monthly_weather$maxtemp) == FALSE), 0) + expect_length(which((monthly_weather$meantemp <= monthly_weather$maxtemp) == FALSE), 0) + expect_length(which((monthly_weather$mintemp <= monthly_weather$meantemp) == FALSE), 0) }) test_that("Newmoon option returns 11 columns", { @@ -43,7 +43,7 @@ test_that("Newmoon option returns 11 columns", { }) test_that("Newmoon temperatures ok", { - expect_equal(length(which((newmoon_weather$mintemp <= newmoon_weather$maxtemp) == FALSE)), 0) - expect_equal(length(which((newmoon_weather$meantemp <= newmoon_weather$maxtemp) == FALSE)), 0) - expect_equal(length(which((newmoon_weather$mintemp <= newmoon_weather$meantemp) == FALSE)), 0) + expect_length(which((newmoon_weather$mintemp <= newmoon_weather$maxtemp) == FALSE), 0) + expect_length(which((newmoon_weather$meantemp <= newmoon_weather$maxtemp) == FALSE), 0) + expect_length(which((newmoon_weather$mintemp <= newmoon_weather$meantemp) == FALSE), 0) }) diff --git a/tests/testthat/test-05-individual-stake-data.R b/tests/testthat/test-05-individual-stake-data.R index cc1c8192..3c84a9b4 100644 --- a/tests/testthat/test-05-individual-stake-data.R +++ b/tests/testthat/test-05-individual-stake-data.R @@ -1,18 +1,18 @@ -context("Check rodent stake data") +# Check rodent stake data portal_data_path <- tempdir() test_that("summarize_individual_rodents returns expected columns", { stake_data <- summarize_individual_rodents(path = portal_data_path) - expect_equal(names(stake_data), c("period","month","day","year","treatment","plot","stake","species", - "sex","reprod","age","testes","vagina","pregnant","nipples","lactation", - "hfl","wgt","tag","note2","ltag","note3")) + expect_named(stake_data, c("period","month","day","year","treatment","plot","stake","species", + "sex","reprod","age","testes","vagina","pregnant","nipples","lactation", + "hfl","wgt","tag","note2","ltag","note3")) filled_stake_data = summarize_individual_rodents(path = portal_data_path, type = "granivores", length = "all", unknowns = T, min_plots = 1, time = "newmoon", fillweight = T) - expect_equal(names(filled_stake_data), c("newmoonnumber","month","day","year","treatment","plot","stake", - "species","sex","reprod","age","testes","vagina","pregnant", - "nipples","lactation","hfl","wgt","tag","note2","ltag","note3")) + expect_named(filled_stake_data, c("newmoonnumber","month","day","year","treatment","plot","stake", + "species","sex","reprod","age","testes","vagina","pregnant", + "nipples","lactation","hfl","wgt","tag","note2","ltag","note3")) }) diff --git a/tests/testthat/test-06-summarize-plants.R b/tests/testthat/test-06-summarize-plants.R index 7b48eea0..c95885d7 100644 --- a/tests/testthat/test-06-summarize-plants.R +++ b/tests/testthat/test-06-summarize-plants.R @@ -1,4 +1,4 @@ -context("Check plant data summaries") +# Check plant data summaries portal_data_path <- tempdir() diff --git a/tests/testthat/test-07-seasons.R b/tests/testthat/test-07-seasons.R index 74cab398..5b8d3085 100644 --- a/tests/testthat/test-07-seasons.R +++ b/tests/testthat/test-07-seasons.R @@ -1,4 +1,4 @@ -context("Check seasonal data summaries") +# Check seasonal data summaries eps <- if (capabilities("long.double")) sqrt(.Machine$double.eps) else diff --git a/tests/testthat/test-08-NDVI.R b/tests/testthat/test-08-NDVI.R index 956c7402..c63ce0d2 100644 --- a/tests/testthat/test-08-NDVI.R +++ b/tests/testthat/test-08-NDVI.R @@ -1,4 +1,4 @@ -context("checks NDVI summary output") +# checks NDVI summary output portal_data_path <- tempdir() monthly_ndvi <- ndvi("monthly", path = portal_data_path) @@ -10,31 +10,31 @@ test_that("Monthly option returns 2 columns", { }) test_that("Newmoon option returns 2 columns", { - expect_that(dim(newmoon_ndvi)[2], equals(2)) - expect_equal(colnames(newmoon_ndvi), c("newmoonnumber", "ndvi")) + expect_equal(dim(newmoon_ndvi)[2], 2) + expect_named(newmoon_ndvi, c("newmoonnumber", "ndvi")) }) test_that("Missing monthly option data are filled", { ndvi_NA <- monthly_ndvi ndvi_NA[10, "ndvi"] <- NA - expect_that(any(is.na(ndvi_NA[, "ndvi"])), equals(TRUE)) + expect_true(anyNA(ndvi_NA[, "ndvi"])) lasttime <- max(ndvi_NA$date) ndvi_NA <- fill_missing_ndvi(ndvi_NA, "monthly", lasttime) - expect_that(any(is.na(ndvi_NA[, "ndvi"])), equals(FALSE)) + expect_false(anyNA(ndvi_NA[, "ndvi"])) }) test_that("Missing moon option data are filled", { ndvi_NA <- newmoon_ndvi ndvi_NA[10, "ndvi"] <- NA - expect_that(any(is.na(ndvi_NA[, "ndvi"])), equals(TRUE)) + expect_true(anyNA(ndvi_NA[, "ndvi"])) lasttime <- max(ndvi_NA$newmoonnumber) ndvi_NA <- fill_missing_ndvi(ndvi_NA, "newmoon", lasttime) - expect_that(any(is.na(ndvi_NA[, "ndvi"])), equals(FALSE)) + expect_false(anyNA(ndvi_NA[, "ndvi"])) }) test_that("Monthly NDVI can be forecast", { fcast_vals <- fcast_ndvi(monthly_ndvi, "monthly", 1) - expect_that(class(fcast_vals[ , "ndvi"]), equals("numeric")) + expect_type(fcast_vals[ , "ndvi"], "double") }) test_that("Newmoon NDVI can be forecast", { @@ -42,5 +42,5 @@ test_that("Newmoon NDVI can be forecast", { file.path(portal_data_path, "PortalData", "Rodents", "moon_dates.csv"), na.strings = c(""), stringsAsFactors = FALSE) fcast_vals <- suppressWarnings(fcast_ndvi(newmoon_ndvi, "newmoon", 1, moons)) - expect_that(class(fcast_vals[ , "ndvi"]), equals("numeric")) + expect_type(fcast_vals[ , "ndvi"], "double") }) diff --git a/tests/testthat/test-09-get-future-moons.R b/tests/testthat/test-09-get-future-moons.R index b07acead..64ddc71c 100644 --- a/tests/testthat/test-09-get-future-moons.R +++ b/tests/testthat/test-09-get-future-moons.R @@ -1,11 +1,11 @@ -context("Check get_future_newmoons") +# Check get_future_newmoons portal_data_path <- tempdir() test_that("get_future_newmoons returns expected results using current newmoons_table", { moons <- load_trapping_data(portal_data_path)$newmoons_table - expect_error(newmoons <- get_future_newmoons(moons, nfuture_newmoons = 12), NA) + expect_no_error(newmoons <- get_future_newmoons(moons, nfuture_newmoons = 12)) expect_equal(dim(newmoons), c(12, 4)) expect_equal(colnames(newmoons), colnames(moons)) expect_equal(newmoons$newmoonnumber, max(moons$newmoonnumber) + seq(12)) diff --git a/tests/testthat/test-10-summarize_ants.R b/tests/testthat/test-10-summarize_ants.R index 1c36870b..f24510ec 100644 --- a/tests/testthat/test-10-summarize_ants.R +++ b/tests/testthat/test-10-summarize_ants.R @@ -1,4 +1,4 @@ -context("Check ant data summaries") +# Check ant data summaries portal_data_path <- tempdir() diff --git a/tests/testthat/test-11-phenocam.R b/tests/testthat/test-11-phenocam.R index 5eb09a1a..570a20e1 100644 --- a/tests/testthat/test-11-phenocam.R +++ b/tests/testthat/test-11-phenocam.R @@ -1,4 +1,4 @@ -context("checks phenocam summary output") +# Checks phenocam summary output portal_data_path <- tempdir() daily_pheno <- tryCatch(phenocam("daily", path = portal_data_path), error = function(e) NULL) @@ -8,7 +8,7 @@ newmoon_pheno <- tryCatch(phenocam("newmoon", path = portal_data_path), error = test_that("Daily option returns 32 columns", { skip_if(is.null(daily_pheno)) expect_equal(NCOL(daily_pheno), 32) - expect_equal(colnames(daily_pheno), + expect_named(daily_pheno, c("date","year","doy","image_count","midday_filename","midday_r","midday_g","midday_b", "midday_gcc","midday_rcc","r_mean","r_std","g_mean","g_std","b_mean","b_std","gcc_mean", "gcc_std","gcc_50","gcc_75","gcc_90","rcc_mean","rcc_std","rcc_50","rcc_75","rcc_90", @@ -19,13 +19,13 @@ test_that("Daily option returns 32 columns", { test_that("Monthly option returns 7 columns", { skip_if(is.null(monthly_pheno)) expect_equal(NCOL(monthly_pheno), 7) - expect_equal(colnames(monthly_pheno), c("year","month","mean_image_count","midday_gcc","midday_rcc", - "gcc_mean","rcc_mean")) + expect_named(monthly_pheno, c("year","month","mean_image_count","midday_gcc","midday_rcc", + "gcc_mean","rcc_mean")) }) test_that("Newmoon option returns 6 columns", { skip_if(is.null(newmoon_pheno)) - expect_that(dim(newmoon_pheno)[2], equals(6)) - expect_equal(colnames(newmoon_pheno), c("newmoonnumber","mean_image_count","midday_gcc","midday_rcc", - "gcc_mean","rcc_mean")) + expect_equal(dim(newmoon_pheno)[2], 6) + expect_named(newmoon_pheno, c("newmoonnumber","mean_image_count","midday_gcc","midday_rcc", + "gcc_mean","rcc_mean")) }) diff --git a/tests/testthat/test-99-regression.R b/tests/testthat/test-99-regression.R index 8368e463..7b694129 100644 --- a/tests/testthat/test-99-regression.R +++ b/tests/testthat/test-99-regression.R @@ -1,5 +1,7 @@ -context("Regression tests for rodent, ant, and plant output") - +# Regression tests for rodent, ant, and plant output +# use 2nd edition for `expect_known_hash()` that has no good replacement in testthat3 +# r-lib/testthat#1101 +testthat::local_edition(2) portal_data_path <- tempdir() test_that("data generated by default setting is same", {