Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for removed records, switch to R CMD CHECK workflow for tests, use default testthat setup #246

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
33bbb9f
add functions for getting github published and local datasets
PietrH Dec 9, 2024
68c3f10
add basic tests for `get_current()`
PietrH Dec 9, 2024
f640e25
Start writing test that fails if too many records are removed
PietrH Dec 9, 2024
a2bc97c
Move tests to testthat default dir
PietrH Dec 9, 2024
8029958
Use R CMD CHECK github action workflow for tests
PietrH Dec 9, 2024
ab46acf
attempt to resolve merge conflict
PietrH Dec 9, 2024
e614350
Merge pull request #245 from riparias/use-rcmd-check-for-tests
PietrH Dec 9, 2024
54f4a2f
Add basic tests for `get_reference()`
PietrH Dec 9, 2024
e06d86d
Merge branch 'test-for-removed-records' of github.com:riparias/rato-o…
PietrH Dec 9, 2024
77795b9
Move `occurrence.csv` to `inst` subfolder
PietrH Dec 10, 2024
fcc396b
Look into inst folder online as well
PietrH Dec 10, 2024
e6af98e
Check for file in `inst`
PietrH Dec 10, 2024
b8c3494
lubridate in suggests, used in tests
PietrH Dec 10, 2024
ec39afe
Read the current occurrence data from installed package root, rather …
PietrH Dec 10, 2024
3f41d52
Update occurrence.csv
PietrH Dec 10, 2024
93e3a82
Switch to httr so we can retry
PietrH Dec 11, 2024
675df5e
cache response and set col classes
PietrH Dec 13, 2024
2674837
fix r cmd check err
PietrH Dec 13, 2024
a5bb260
Add check for deletion of records
PietrH Dec 13, 2024
1eaf628
fix r cmd check err
PietrH Dec 13, 2024
1b23b9b
Merge branch 'main' into test-for-removed-records
PietrH Jan 3, 2025
f2b6126
run all tests, install first
PietrH Jan 3, 2025
1f54be3
Merge branch 'test-for-removed-records' of github.com:riparias/rato-o…
PietrH Jan 3, 2025
81c93d3
Add tests for column reordering
PietrH Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^LICENSE\.md$
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
47 changes: 47 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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, master]
pull_request:

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
3 changes: 2 additions & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ jobs:
run: |
devtools::install(quick = TRUE)
library(rato.occurrences)
source("tests/test_dwc_occurrence.R")
library(testthat)
testthat::test_dir("tests/testthat/")
shell: Rscript {0}
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ Depends:
R (>= 2.10)
LazyData: true
Config/testthat/edition: 3
Suggests:
lubridate
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(get_current)
export(get_objects)
export(get_reference)
export(get_token)
export(list_object_ids)
export(set_dwc_order)
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#' to be included in this dataset. Checks are run against this list to detect
#' when new species are added.
#'
#' @format ## `species` A vector with over 30 species names.
#' @format `species` A vector with over 30 species names.
"species"
34 changes: 34 additions & 0 deletions R/get_current.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Get the version of the dataset as currently present locally. Called current
#' in tests.
#'
#' This version might be different from the reference dataset [get_reference()]
#' if new data was fetched and mapped but not yet published to Github. For
#' example during an automatic publishing run, or while a new verion of the
#' dataset is still in review.
#'
#' @return A data.frame with DwC mapping of the dataset, as present on the repo.
#' @export
#'
#' @examplesIf interactive()
#' get_current()
get_current <- function() {

# `occurrence.csv` is stored in inst/data/processed/occurrence.csv, everything
# stored in inst is placed into the package root after installing. Thus in
# data/processed/occurrence.csv, but when directly navigating the repo, the
# file still remains in inst.

data_object_path <-
system.file("data/processed", package = "rato.occurrences")

# Make sure data_object_path exists
assertthat::assert_that(
dir.exists(data_object_path)
)

readr::read_csv(
file.path(data_object_path, "occurrence.csv"),
show_col_types = FALSE,
progress = FALSE
)
}
62 changes: 62 additions & 0 deletions R/get_reference.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' Get the version of the dataset as published on Github, called reference in
#' tests
#'
#' This version might be different from the one on GBIF, as the IPT only fetches
#' the data from GITHUB periodically (once a week) and not necessarily in phase
#' with the updates on Github.
#'
#' @return A data.frame with DwC mapping of the dataset, as currently published
#' on Github.
#' @export
#'
#' @examplesIf interactive()
#' get_reference()
get_reference <- function() {
github_csv_url <-
paste0(
"https://raw.githubusercontent.com/riparias/rato-occurrences/main/",
"inst/data/processed/occurrence.csv"
)

httr2::request(github_csv_url) %>%
httr2::req_retry() %>%
httr2::req_cache(path = tempdir(), max_age = 600) %>%
httr2::req_perform() %>%
httr2::resp_body_raw() %>%
rawToChar() %>%
readr::read_csv(show_col_types = FALSE,
progress = FALSE,
col_types =
readr::cols(
occurrenceID = readr::col_character(),
occurrenceStatus = readr::col_character(),
eventID = readr::col_double(),
scientificName = readr::col_character(),
eventDate = readr::col_datetime(format = ""),
organismQuantity = readr::col_double(),
organismQuantityType = readr::col_character(),
samplingProtocol = readr::col_character(),
samplingEffort = readr::col_character(),
municipality = readr::col_character(),
verbatimLatitude = readr::col_double(),
verbatimLongitude = readr::col_double(),
verbatimCoordinateSystem = readr::col_character(),
verbatimSRS = readr::col_character(),
decimalLatitude = readr::col_double(),
decimalLongitude = readr::col_double(),
coordinateUncertaintyInMeters = readr::col_double(),
countryCode = readr::col_character(),
geodeticDatum = readr::col_character(),
type = readr::col_character(),
language = readr::col_character(),
license = readr::col_character(),
rightsHolder = readr::col_character(),
datasetID = readr::col_character(),
institutionCode = readr::col_character(),
datasetName = readr::col_character(),
basisOfRecord = readr::col_character(),
recordedBy = readr::col_character(),
kingdom = readr::col_character(),
taxonRank = readr::col_character()
))
}
18 changes: 9 additions & 9 deletions R/set_dwc_order.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ set_dwc_order <- function(x){
assertthat::assert_that(is.data.frame(x))
dplyr::relocate(
x,
occurrenceID,
occurrenceStatus,
eventID,
scientificName,
eventDate,
"occurrenceID",
"occurrenceStatus",
"eventID",
"scientificName",
"eventDate",
dplyr::starts_with("organism"),
dplyr::starts_with("sampling"),
municipality,
"municipality",
dplyr::starts_with("verbatim"),
dplyr::starts_with("decimal"),
coordinateUncertaintyInMeters,
countryCode,
geodeticDatum
"coordinateUncertaintyInMeters",
"countryCode",
"geodeticDatum"

)
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!-- badges: start -->
[![funding](https://img.shields.io/static/v1?label=published+through&message=LIFE+RIPARIAS&labelColor=00a58d&color=ffffff)](https://www.riparias.be/)
[![fetch-data](https://github.com/riparias/rato-occurrences/actions/workflows/fetch-data.yaml/badge.svg)](https://github.com/riparias/rato-occurrences/actions/workflows/fetch-data.yaml)
[![mapping and testing](https://github.com/riparias/rato-occurrences/actions/workflows/mapping_and_testing.yaml/badge.svg)](https://github.com/riparias/rato-occurrences/actions/workflows/mapping_and_testing.yaml)
[![R-CMD-check](https://github.com/riparias/rato-occurrences/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/riparias/rato-occurrences/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

## Rationale

Expand Down
Loading
Loading