Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 13th edition Keys taxonomic codes #41

Merged
merged 1 commit into from
Mar 10, 2023
Merged
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
16 changes: 15 additions & 1 deletion R/data-documentation.R
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
#' @title Soil Taxonomy Hierarchy
#'
#' @description The first 4 levels of the US Soil Taxonomy hierarchy (soil order, suborder, greatgroup, subgroup), presented as a \code{data.frame} (denormalized) and a \code{list} of unique taxa.
#'
#' @details Ordered based on the unique letter codes denoting taxa from the 13th edition of the Keys to Soil Taxonomy.
#' @usage data(ST)
#'
#' @references
@@ -81,3 +81,17 @@
#'
"ST_higher_taxa_codes_12th"

#' @title Letter Code Lookup Table for Position of Taxa within the Keys to Soil Taxonomy (13th Edition)
#'
#' @description A lookup table mapping unique taxonomic Order, Suborder, Great Group and Subgroups to letter codes that denote their logical position within the Keys.
#'
#' @references
#'
#' Soil Survey Staff. 2022. Keys to Soil Taxonomy, 13th ed. USDA-Natural Resources Conservation Service.
#' \url{https://www.nrcs.usda.gov/resources/guides-and-instructions/keys-to-soil-taxonomy}
#'
#' @usage data(ST_higher_taxa_codes_13th)
#'
#' @keywords datasets
#'
"ST_higher_taxa_codes_13th"
15 changes: 9 additions & 6 deletions data-raw/package-datasets.R
Original file line number Diff line number Diff line change
@@ -63,28 +63,31 @@ write.csv(ST.family.classes, file='data-raw/ST-family-classes.csv', row.names=FA
ST <- read.csv('data-raw/ST-full.csv', stringsAsFactors = FALSE)
usethis::use_data(ST, overwrite = TRUE)

ST_logic <- cbind(ST, )

## unique taxa, sorted by appearance in the 'Keys
## as a list
ST_unique_list <- list()

# requires codes / taxa list
load('data/ST_higher_taxa_codes_12th.rda')
load('data/ST.rda')

# requires codes / taxa list
ST_higher_taxa_codes_13th <- jsonlite::fromJSON("https://raw.githubusercontent.com/ncss-tech/SoilKnowledgeBase/main/inst/extdata/KST/2022_KST_codes.json")
colnames(ST_higher_taxa_codes_13th) <- c("code", "taxon")
usethis::use_data(ST_higher_taxa_codes_13th, overwrite = TRUE)

latest_taxa <- ST_higher_taxa_codes_13th

# re-arrange taxa according to letter codes in the 'Keys
.uniqueTaxaLogicalOrdering <- function(x) {
# find taxa in the letter code LUT
idx <- match(tolower(x), tolower(ST_higher_taxa_codes_12th$taxon))
idx <- match(tolower(x), tolower(latest_taxa$taxon))

# missing taxa
if (any(is.na(idx))) {
message(sprintf('missing: %s', paste(x[which(is.na(idx))], collapse = ',')))
}

# sort taxa based on letter codes
res <- ST_higher_taxa_codes_12th$taxon[idx][order(ST_higher_taxa_codes_12th$code[idx])]
res <- latest_taxa$taxon[idx][order(latest_taxa$code[idx])]

return(tolower(res))
}
Binary file added data/ST_higher_taxa_codes_13th.rda
Binary file not shown.
Binary file modified data/ST_unique_list.rda
Binary file not shown.
3 changes: 3 additions & 0 deletions man/ST.Rd

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

20 changes: 20 additions & 0 deletions man/ST_higher_taxa_codes_13th.Rd

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