Skip to content

Commit 90368d6

Browse files
Merge pull request #185 from pfmc-assessments/fix-species-lookup
fix species check when there are two listings
2 parents 487d4e2 + 05f9377 commit 90368d6

File tree

5 files changed

+27
-39
lines changed

5 files changed

+27
-39
lines changed

R/SurveyAgeAtLen.fn.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#' unexpanded sample numbers.
2424
#' @param NAs2zero A logical specifying if `NA`s should be changed to zeros.
2525
#' The default is `TRUE`.
26+
#' @param ageErr Deprecated.
2627
#' @inheritParams get_expanded_comps
2728
#' @param returnSamps A logical with the default of `FALSE`. A value of `TRUE`
2829
#' stops the function after the sample size is calculated.

R/get_species_info.R

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,14 @@
2626
#' @author Kelli Faye Johnson
2727
#' @examples
2828
#' get_species_info(c("sablefish", "petrale"))
29-
#' # Expect a warning because vermilion doesn't have an strata assigned to it
29+
#' get_species_info(c("vermilion"))
3030
#' testthat::expect_message(
31-
#' get_species_info(c("vermilion"))
32-
#' )
33-
#' # Dusky returns multiple entries
34-
#' testthat::expect_message(
35-
#' get_species_info(c("dusky"))
31+
#' get_species_info(c("chilipepper"))
3632
#' )
3733
#'
3834
get_species_info <- function(species, unident = FALSE, verbose = TRUE) {
3935
# background information
40-
sppnames <- nwfscSurvey::PullSpp.fn()
36+
sppnames <- pull_spp()
4137
if (!unident) {
4238
sppnames <- sppnames[!grepl("unident", sppnames[["common"]]), ]
4339
}
@@ -55,6 +51,7 @@ get_species_info <- function(species, unident = FALSE, verbose = TRUE) {
5551
c("coast", "curlfin_sole", "flatfish"),
5652
c("coast", "darkblotched_rockfish", "shelfrock"),
5753
c("coast", "dover_sole", "flatfish"),
54+
c("coast", "dusky_rockfish", "shelfrock"),
5855
c("coast", "english_sole", "flatfish"),
5956
c("wa_or", "flathead_sole", "flatfish"),
6057
c("coast", "greenspotted_rockfish", "shelfrock"),
@@ -114,42 +111,37 @@ get_species_info <- function(species, unident = FALSE, verbose = TRUE) {
114111

115112
# Match strata
116113
index <- match(tolower(out[, "common_name"]), tolower(spplist[, 2]))
117-
if (any(is.na(index))) {
118-
bad <- which(is.na(index))
119-
bad_strata <- paste(unique(out[bad, "input"]), collapse = ", ")
114+
if (sum(is.na(index)) == length(index)) {
115+
index <- grep(species, tolower(out[, "common_name"]))[1]
116+
out <- out[index, ]
117+
} else {
120118
if (any(is.na(index))) {
121-
cli::cli_alert_warning(
122-
"The following species were not found in the look up table stored in
123-
get_species_info(), please self-assign strata and species_type:
124-
{bad_strata}."
125-
)
126-
}
119+
bad <- which(is.na(index))
120+
bad_strata <- paste(unique(out[bad, "input"]), collapse = ", ")
127121

128-
if (length(index) != 1) {
129-
if (verbose) {
130-
multi_matches <- paste(unique(out[bad, "common_name"]), collapse = ", ")
131-
cli::cli_alert_warning(
132-
"Multiple matches were found for the {species} in the look up table
133-
stored in PullSpp.fn(). Only one match is returned.
134-
The common_name for the removed match is: {multi_matches}."
135-
)
122+
if (length(index) != 1) {
123+
if (verbose) {
124+
multi_matches <- paste(unique(out[bad, "common_name"]), collapse = ", ")
125+
cli::cli_alert_warning(
126+
"Multiple matches were found for the {species} in the look up table
127+
stored in pull_spp(). Only one match is returned. The common_name for the removed match is: {multi_matches}."
128+
)
129+
}
136130
}
137-
}
138-
if (sum(!is.na(index)) == length(index)) {
139131
out <- out[!is.na(index), ]
140132
index <- index[!is.na(index)]
141133
}
142134
}
143135

144136
out[, "strata"] <- ifelse(
145-
test = is.na(index),
137+
test = is.na(index[1]),
146138
yes = "coast",
147-
no = spplist[index, 1]
139+
no = spplist[index[1], 1]
148140
)
149141
out[, "species_type"] <- ifelse(
150-
test = is.na(index),
142+
test = is.na(index[1]),
151143
yes = "all",
152-
no = spplist[index, 3]
144+
no = spplist[index[1], 3]
153145
)
154146

155147
return(out)

R/pull_bio.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pull_bio <- function(
100100
"tow", "datetime_utc_iso", "depth_m", "weight_kg", "ageing_lab", "otosag_id",
101101
"length_cm", "width_cm", "sex", "age_years", "latitude_dd", "longitude_dd",
102102
"performance", "station_invalid",
103-
"ageing_laboratory_dim$laboratory",
104103
"standard_survey_age_indicator",
105104
"standard_survey_length_or_width_indicator",
106105
"standard_survey_weight_indicator",
@@ -203,7 +202,6 @@ pull_bio <- function(
203202
}
204203

205204
colnames(bio_pull)[colnames(bio_pull) == "actual_station_design_dim$reason_station_invalid"] <- "reason_station_invalid"
206-
colnames(bio_pull)[colnames(bio_pull) == "standard_survey_length_or_width_indicator"] <- "ageing_lab"
207205
colnames(bio_pull)[colnames(bio_pull) == "operation_dim$legacy_performance_code"] <- "legacy_performance_code"
208206
bio_pull$weight <- bio_pull$weight_kg
209207
bio_pull$age <- bio_pull$age_years
@@ -250,7 +248,6 @@ pull_bio <- function(
250248
len_pull$date <- chron::chron(format(as.POSIXlt(len_pull$datetime_utc_iso, format = "%Y-%m-%dT%H:%M:%S"), "%Y-%m-%d"), format = "y-m-d", out.format = "YYYY-m-d")
251249
len_pull$trawl_id <- as.character(len_pull$trawl_id)
252250
colnames(len_pull)[colnames(len_pull) == "actual_station_design_dim$reason_station_invalid"] <- "reason_station_invalid"
253-
colnames(len_pull)[colnames(len_pull) == "standard_survey_length_or_width_indicator"] <- "ageing_lab"
254251
colnames(len_pull)[colnames(len_pull) == "operation_dim$legacy_performance_code"] <- "legacy_performance_code"
255252
}
256253

man/SurveyAgeAtLen.fn.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_species_info.Rd

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)