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# '
3834get_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 )
0 commit comments