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

get_NASIS_table_name_by_purpose: Add basal area tables #367

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
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
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"
),
brownag marked this conversation as resolved.
Show resolved Hide resolved
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)))
}
Loading