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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: A programmatic interface to the Web Service methods
retrieving information on data providers, getting species occurrence
records, getting counts of occurrence records, and using the GBIF
tile map service to make rasters summarizing huge amounts of data.
Version: 3.8.4.1
Version: 3.8.4.2
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = "aut", comment = c("0000-0003-1444-9135")),
Expand Down
11 changes: 10 additions & 1 deletion R/name_backbone.r
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ process_name_backbone_output <- function(tt, args) {
} else {
NULL
}
acceptedUsage <- if (!is.null(tt$acceptedUsage)) {
a <- tibble::as_tibble(tt$acceptedUsage)[c("key","name")]
colnames(a)[colnames(a) == "key"] <- "acceptedUsageKey"
colnames(a)[colnames(a) == "name"] <- "acceptedScientificName"
Comment on lines +266 to +268
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The acceptedUsage processing subsets only the "key" and "name" fields, which is inconsistent with how the usage object is processed (lines 231-235). The usage processing converts the entire object to a tibble and then renames specific columns. Consider following the same pattern here: convert the entire acceptedUsage object to a tibble first, then rename the columns, to maintain consistency and allow any additional fields from the API to be included.

Suggested change
a <- tibble::as_tibble(tt$acceptedUsage)[c("key","name")]
colnames(a)[colnames(a) == "key"] <- "acceptedUsageKey"
colnames(a)[colnames(a) == "name"] <- "acceptedScientificName"
a <- tibble::as_tibble(tt$acceptedUsage)
if ("key" %in% colnames(a)) colnames(a)[colnames(a) == "key"] <- "acceptedUsageKey"
if ("name" %in% colnames(a)) colnames(a)[colnames(a) == "name"] <- "acceptedScientificName"

Copilot uses AI. Check for mistakes.
a
} else {
NULL
}
verbatim <- if (!is.null(args)) {
input_args_clean <- args[!names(args) %in%
c("strict","verbose","start","limit","curlopts")]
Expand All @@ -273,7 +281,8 @@ process_name_backbone_output <- function(tt, args) {
} else {
NULL
}
out <- do.call("cbind", rgbif_compact(list(usage,
out <- do.call("cbind", rgbif_compact(list(usage,
acceptedUsage,
diagnostics,
classification,
synonym,
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/name_backbone_acceptedUsageKey.yml

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

11 changes: 11 additions & 0 deletions tests/testthat/test-name_backbone.r
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ test_that("name_backbone verbose=TRUE", {
expect_true(all(vv$verbatim_name == "Calopteryx"))
expect_true(nrow(vv) > nrow(tt))
})

test_that("name_backbone returns acceptedUsageKey", {
vcr::use_cassette("name_backbone_acceptedUsageKey", {
aa <- name_backbone(name = 'Anastrophyllum minutum')
})
expect_is(aa, "tbl")
expect_is(aa, "tbl_df")
expect_is(aa, "data.frame")
expect_true("acceptedUsageKey" %in% colnames(aa))
expect_true("acceptedScientificName" %in% colnames(aa))
Comment on lines +138 to +139
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verifies that the columns exist but doesn't check their actual values. Based on the fixture data, the test should verify that acceptedUsageKey is "2689422" and acceptedScientificName is "Sphenolobus minutus (Schreb. ex Cranz) Berggr." to ensure the function correctly extracts these values from the API response.

Copilot uses AI. Check for mistakes.
})
Loading