Skip to content

Commit

Permalink
Make latest checking more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
willgearty committed Sep 30, 2024
1 parent 9972583 commit 0f9c458
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions R/rl_taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ rl_sis_latest <- function(id, key = NULL, parse = TRUE, ...) {
assert_is(parse, "logical")

Check warning on line 52 in R/rl_taxa.R

View check run for this annotation

Codecov / codecov/patch

R/rl_taxa.R#L52

Added line #L52 was not covered by tests

tmp <- rl_sis(id, key, ...)$assessments
tmp_sub <- subset(tmp, tmp$latest)
tmp_sub <- tmp_sub[order(tmp_sub$year_published, decreasing = TRUE), ]
if (any(tmp$latest, na.rm = TRUE)) {
tmp_sub <- subset(tmp, tmp$latest)

Check warning on line 56 in R/rl_taxa.R

View check run for this annotation

Codecov / codecov/patch

R/rl_taxa.R#L54-L56

Added lines #L54 - L56 were not covered by tests
}
tmp_sub$year_published <- as.numeric(as.character(tmp_sub$year_published))
ord <- order(tmp_sub$year_published, decreasing = TRUE)
tmp_sub <- tmp_sub[ord, , drop = FALSE]
rl_assessment(id = tmp_sub$assessment_id[1], key = key, parse = parse, ...)

Check warning on line 61 in R/rl_taxa.R

View check run for this annotation

Codecov / codecov/patch

R/rl_taxa.R#L58-L61

Added lines #L58 - L61 were not covered by tests
}

Expand Down Expand Up @@ -166,8 +170,12 @@ rl_species_latest <- function(genus, species, infra = NULL,

tmp <- rl_species(genus, species, infra = infra,
subpopulation = subpopulation, key, ...)$assessments
tmp_sub <- subset(tmp, tmp$latest)
tmp_sub <- tmp_sub[order(tmp_sub$year_published, decreasing = TRUE), ]
if (any(tmp$latest, na.rm = TRUE)) {
tmp_sub <- subset(tmp, tmp$latest)

Check warning on line 174 in R/rl_taxa.R

View check run for this annotation

Codecov / codecov/patch

R/rl_taxa.R#L171-L174

Added lines #L171 - L174 were not covered by tests
}
tmp_sub$year_published <- as.numeric(as.character(tmp_sub$year_published))
ord <- order(tmp_sub$year_published, decreasing = TRUE)
tmp_sub <- tmp_sub[ord, , drop = FALSE]
rl_assessment(id = tmp_sub$assessment_id[1], key = key, parse = parse, ...)

Check warning on line 179 in R/rl_taxa.R

View check run for this annotation

Codecov / codecov/patch

R/rl_taxa.R#L176-L179

Added lines #L176 - L179 were not covered by tests
}

Expand Down

0 comments on commit 0f9c458

Please sign in to comment.