Skip to content

Commit

Permalink
Upkeep - improve messages + CI (#299)
Browse files Browse the repository at this point in the history
* Fix tidyselect 1.2.0 warning
* Use testthat 3rd edition, use snapshot tests to test for messages
  Remove deprecated `expect_that()`,`expect_is()` -> `expect_type()` or `expect_s3_class()`
* Lint test with simpler more recent testthat syntax
* Use latest pkgdwon to add a search bar. Add favicons and move logo to logo.png for pkgdown to recognize it.
redocument()
* Drop crayon and clisymbols for cli and enable color in test (will make it easier in RStudio).
* Update test-03-summarize-rodents.R
* Update CI to latest with `usethis::use_github_action()`

---------

Co-authored-by: henrykironde <[email protected]>
  • Loading branch information
olivroy and henrykironde authored Aug 8, 2024
1 parent 76c2f9d commit 560de90
Show file tree
Hide file tree
Showing 44 changed files with 320 additions and 230 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
^paper$
^.Renviron$
^_pkgdown\.yml$
^pkgdown$
^\.github$
^man/figures/portalr.png$
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand All @@ -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")'
46 changes: 29 additions & 17 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 0 additions & 34 deletions .github/workflows/test-coverage.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 5 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
14 changes: 10 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
41 changes: 25 additions & 16 deletions R/download_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -113,17 +114,20 @@ 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())

}

}

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...")
}

Expand Down Expand Up @@ -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(\"<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)
Expand Down Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion R/load_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading

0 comments on commit 560de90

Please sign in to comment.