Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.
#
# NSR modification: the "Add the drat repository" step in both jobs below, so
# pak can install rWCVPdata (Suggests), which isn't on CRAN. pak does not read
# DESCRIPTION's Additional_repositories. Keep that step if this file is
# regenerated with rhub::rhub_setup().

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"
Expand Down Expand Up @@ -56,6 +61,20 @@ jobs:
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- name: Add the drat repository for rWCVPdata
run: |
# rWCVPdata (Suggests) isn't on CRAN: add the repository named in
# DESCRIPTION's Additional_repositories to every later R session.
# utils is loaded first because 'repos' isn't set yet while profiles
# run, and utils won't set its defaults once something else has.
f <- Sys.getenv("R_PROFILE_USER")
if (!nzchar(f)) f <- path.expand("~/.Rprofile")
line <- paste('local({ loadNamespace("utils");',
'options(repos = c(getOption("repos"),',
'rWCVPdata = "https://matildabrown.github.io/drat")) })')
write(line, file = f, append = TRUE)
message("Added to ", f, ": ", line)
shell: Rscript {0}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
Expand Down Expand Up @@ -85,6 +104,20 @@ jobs:
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- name: Add the drat repository for rWCVPdata
run: |
# rWCVPdata (Suggests) isn't on CRAN: add the repository named in
# DESCRIPTION's Additional_repositories to every later R session.
# utils is loaded first because 'repos' isn't set yet while profiles
# run, and utils won't set its defaults once something else has.
f <- Sys.getenv("R_PROFILE_USER")
if (!nzchar(f)) f <- path.expand("~/.Rprofile")
line <- paste('local({ loadNamespace("utils");',
'options(repos = c(getOption("repos"),',
'rWCVPdata = "https://matildabrown.github.io/drat")) })')
write(line, file = f, append = TRUE)
message("Added to ", f, ": ", line)
shell: Rscript {0}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ Suggests:
terra,
testthat,
devtools,
BIEN,
TNRS,
vcr (>= 0.6.0),
withr
Additional_repositories: https://matildabrown.github.io/drat
VignetteBuilder: knitr
VignetteBuilder: knitr, rmarkdown
RoxygenNote: 7.3.3
48 changes: 9 additions & 39 deletions R/NSR_from_coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,18 @@
#' @import httr
#' @keywords internal
#' @examples \dontrun{
#'library(BIEN)
#'# Species and coordinates, with an id for each record
#'occs <- data.frame(species = c("Acer rubrum", "Acer rubrum", "Acer platanoides"),
#' latitude = c(45.50, 51.51, 45.50),
#' longitude = c(-73.57, -0.13, -73.57),
#' id = c("1", "2", "3"))
#'
#'# Get some data
#'results <- NSR:::NSR_from_coordinates(occurrence_dataframe = occs)
#'
#'ar_occs <- BIEN_occurrence_species(species = "Acer rubrum",
#' natives.only = FALSE,
#' political.boundaries = TRUE,
#' limit=100)
#'# Join the results back to the input
#'merge(occs, results, by.x = "id", by.y = "input_id")
#'}
#'
#'
#'# Rename columns so that we can differentiate between coordinates declared
#'# and coordinates inferred
#'
#'colnames(ar_occs)[which(colnames(ar_occs)=="country")] <- "country_declared"
#'colnames(ar_occs)[which(colnames(ar_occs)=="state_province")] <- "state_declared"
#'colnames(ar_occs)[which(colnames(ar_occs)=="county")] <- "county_declared"
#'
#'# Select needed fields and add an ID column
#'
#'ar_occs_subset <- ar_occs[c("scrubbed_species_binomial","latitude","longitude")]
#'
#'# Toss duplicates (speeds up processing)
#'
#'ar_occs_subset <- unique(ar_occs_subset)
#'
#'# Add an id column
#'
#'ar_occs_subset$id <- as.character(1:nrow(ar_occs_subset))
#'
#'# Get results
#'
#'results_ar <- NSR:::NSR_from_coordinates(occurrence_dataframe = ar_occs_subset)
#'
#'# Join results back to original data
#'
#'results_ar <- ar_occs_subset |>
#' merge(y = results_ar,by.x = c("id"),
#' by.y = c("input_id"))
#'
#'ar_occs <- ar_occs |> merge(results_ar,
#' by = c("latitude","longitude","scrubbed_species_binomial"))
#' }
NSR_from_coordinates <- function(occurrence_dataframe,
...){

Expand Down
48 changes: 9 additions & 39 deletions man/NSR_from_coordinates.Rd

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

14 changes: 9 additions & 5 deletions tests/testthat/setup-nsr.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ url <- "https://nsrapi.xyz/nsr_wsb.php" # production
# url <- "www.google.com"
# url <- "www.hisstank.com"

library("vcr") # *Required* as vcr is set up on loading
# vcr is in Suggests: without it (as in CRAN's no-Suggests checks) the tests that replay
# recorded API responses skip themselves
if (requireNamespace("vcr", quietly = TRUE)) {
library("vcr") # *Required* as vcr is set up on loading

invisible(vcr::vcr_configure(
dir = vcr::vcr_test_path("fixtures")
))
invisible(vcr::vcr_configure(
dir = vcr::vcr_test_path("fixtures")
))

vcr::check_cassette_names()
vcr::check_cassette_names()
}
2 changes: 2 additions & 0 deletions tests/testthat/test-NSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ context("nsr main")
test_that("example works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_example", {

results <- NSR(occurrence_dataframe = nsr_testfile,
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-NSR_citations.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ test_that("example works", {
# skip_if_offline(host = "r-project.org")


skip_if_not_installed("vcr")

vcr::use_cassette("nsr_citations", {
citation_info <- NSR_citations(
url = url,
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-NSR_data_dictionary.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ test_that("example works", {
# skip_if_offline(host = "r-project.org")


skip_if_not_installed("vcr")

vcr::use_cassette("nsr_dd", {

NSR_fields <- NSR_data_dictionary(url = url,
Expand All @@ -22,6 +24,8 @@ test_that("example2 works", {
# skip_if_offline(host = "r-project.org")


skip_if_not_installed("vcr")

vcr::use_cassette("nsr_dd_status", {

NSR_status <- NSR_data_dictionary(native_status = TRUE,
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-NSR_political_divisions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ context("nsr pol divs")
test_that("example works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_poldivs", {

nsr_poldivs <- NSR_political_divisions(by_country = TRUE)
Expand All @@ -22,6 +24,8 @@ test_that("example works", {
test_that("example 2 works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_checklist", {

nsr_checklists <- NSR_political_divisions(by_country = FALSE)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-NSR_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ context("nsr simple")
test_that("example works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_simple_example", {

results <- NSR_simple(species = "Acer rubrum",
Expand All @@ -25,6 +27,8 @@ test_that("example works", {
test_that("second example works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_simple_example2", {

results2 <- NSR_simple(species = c("Acer rubrum", "Aspen tremuloides") ,
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-NSR_sources.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ test_that("example works", {
# skip_if_offline(host = "r-project.org")


skip_if_not_installed("vcr")

vcr::use_cassette("nsr_sources", {
sources <- NSR_sources(
url = url,
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-NSR_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ context("nsr version")
test_that("example works", {
# skip_if_offline(host = "r-project.org")

skip_if_not_installed("vcr")

vcr::use_cassette("nsr_version", {
NSR_version_metadata <- NSR_version(
url = url,
Expand Down
Loading