-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX(PullCatch.PacFIN): nominal code wasn't working for some species
* pulled out nominal code into PullNominal.PacFIN * much better code to search for nominal code * create an issue regarding should other types of catches be included? #55
- Loading branch information
1 parent
5123e21
commit 8b32b2a
Showing
4 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' Pull the species information table and return nominal code | ||
#' | ||
#' Pull the species information table with PACFIN_SPECIES_CODE and | ||
#' PACFIN_COMMON_NAME from PacFIN to determine the nominal code for | ||
#' a given species code. | ||
#' | ||
#' @template pacfin_species_code | ||
#' @template username | ||
#' @template password | ||
#' @importFrom magrittr %>% | ||
#' @return A vector of character values, where each value is a | ||
#' PACFIN_SPECIES_CODE that pertains to the input `pacfin_species_code`. | ||
#' `NA` is returned if no values are found. | ||
#' | ||
PullNominal.PacFIN <- function(pacfin_species_code, username, password) { | ||
|
||
spp <- getDB(sql.species(), | ||
username = username, password = password | ||
) | ||
|
||
nom <- spp[grepl("NOM\\.", spp[,2]), ] | ||
|
||
thenominal <- tibble::tibble(spp) %>% | ||
dplyr::mutate(searchname = gsub( | ||
"BLACK AND YELLOW", | ||
"BLACK-AND-YELLOW", | ||
PACFIN_SPECIES_COMMON_NAME | ||
)) %>% | ||
dplyr::mutate(searchname = gsub( | ||
"CALIFORNIA HALIBUT", | ||
"CALIF HALIBUT", | ||
searchname | ||
)) %>% | ||
dplyr::mutate(searchname = gsub( | ||
"PACIFIC OCEAN PERCH", | ||
"POP", | ||
searchname | ||
)) %>% | ||
dplyr::mutate(searchname = gsub( | ||
"(CHILIPEPPER|SQUARESPOT|VERMILION) ROCKFISH", | ||
"\\1", | ||
searchname | ||
)) %>% | ||
dplyr::mutate(nominal = purrr::map_chr(searchname, | ||
~paste0(grep(.x, nom[, 2], value = TRUE), collapse = "|"))) %>% | ||
dplyr::mutate(code = purrr::map(nominal, ~{ | ||
if (.x[1] == "") return(NA) | ||
return(nom[grep(.x, nom[, 2]), 1]) | ||
})) %>% | ||
dplyr::filter(PACFIN_SPECIES_CODE == pacfin_species_code) %>% | ||
dplyr::pull(code) %>% | ||
unlist() | ||
|
||
return(thenominal) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.