Skip to content

Commit

Permalink
Add basal area tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roe authored and Roe committed Nov 30, 2024
1 parent dc11538 commit 95e8cb4
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions R/get_NASIS_table_name_by_purpose.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Get NASIS 7 Physical Table Names
#'
#' Get NASIS 7 Physical Table Names
#'
#' Method generalizing concepts of NASIS 7 data model to group tables by "purpose." Most of our more complex queries rely on tables from one or more purposes, so individual higher-level functions might call a function like this to identify the relevant tables from a data source.
#'
#'
#' @param purpose character. One or more of: "metadata", "lookup", "nasis", "site", "pedon", "transect", "component", "vegetation", "project", "techsoilservice", "area", "soilseries", "legend", "mapunit", "datamapunit"
#' @param SS append "_View_1" on appropriate tables? Default: FALSE
#'
Expand All @@ -12,30 +12,30 @@
#' \dontrun{
#' # get the "site" table names
#' get_NASIS_table_name_by_purpose("site")
#'
#'
#' # get the pedon table names
#' get_NASIS_table_name_by_purpose("pedon", SS = TRUE)
#'
#'
#' # metadata and lookup not affected by SS argument, but site and pedon are
#' get_NASIS_table_name_by_purpose(c("metadata", "lookup",
#' "site", "pedon"), SS = TRUE)
#' }
#'
get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "nasis", "site",
"pedon", "transect", "component",
"vegetation", "project",
#'
get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "nasis", "site",
"pedon", "transect", "component",
"vegetation", "project",
"techsoilservice", "area",
"soilseries", "legend",
"mapunit", "datamapunit"),
SS = FALSE) {

# TODO: store as .rda?
table_groups <- list(
metadata = c(
"MetadataDomainDetail",
"MetadataDomainMaster",
"MetadataTableColumn",
"MetadataTable",
"MetadataTableColumn",
"MetadataTable",
"MetadataColumnLookup",
"MetadataIndexDetail"
),
Expand Down Expand Up @@ -118,7 +118,7 @@ get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "n
component = c(
"component",
"chorizon",
"chfrags",
"chfrags",
"chhuarts",
"chtexturegrp",
"chstructgrp",
Expand Down Expand Up @@ -168,7 +168,8 @@ get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "n
"comparativeyielddata",
"comparativeyieldrefquadrats",
"pointplantcoverdetails",
"plantprodquadratdetails"
"plantprodquadratdetails",
"plotspeciesbasalarea"
),
project = c(
"project",
Expand Down Expand Up @@ -202,33 +203,33 @@ get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "n
datamapunit = "datamapunit",
nasis = c("nasisgroup", "nasisuser")
)
uses_View_1 <- list("metadata" = FALSE,
"lookup" = FALSE,
"site" = TRUE,
"pedon" = TRUE,
"transect" = TRUE,
"component" = TRUE,

uses_View_1 <- list("metadata" = FALSE,
"lookup" = FALSE,
"site" = TRUE,
"pedon" = TRUE,
"transect" = TRUE,
"component" = TRUE,
"vegetation" = TRUE,
"project" = TRUE,
"techsoilservice" = TRUE,
"techsoilservice" = TRUE,
"area" = TRUE,
"soilseries" = FALSE,
"legend" = TRUE,
"mapunit" = TRUE,
"legend" = TRUE,
"mapunit" = TRUE,
"datamapunit" = TRUE,
"nasis" = FALSE)

purpose <- match.arg(purpose, names(table_groups), several.ok = TRUE)

res <- table_groups[purpose]

res <- lapply(seq_along(res), function(i) {
ni <- names(res)[i]
if (uses_View_1[[ni]] && SS)
if (uses_View_1[[ni]] && SS)
return(paste0(res[[ni]], "_View_1"))
else return(res[[ni]])
})

return(as.character(unlist(res)))
}

0 comments on commit 95e8cb4

Please sign in to comment.