Skip to content

Commit

Permalink
Merge pull request #366 from natearoe/roe
Browse files Browse the repository at this point in the history
fetchVegdata: add siteobsiid to vegplot tables; activate vegbasalarea table
  • Loading branch information
brownag authored Nov 18, 2024
2 parents 1c10e5a + f549a7b commit dc11538
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 59 deletions.
22 changes: 12 additions & 10 deletions R/fetchVegdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
#' get_vegplot_transpecies_from_NASIS_db
#' get_vegplot_tree_si_details_from_NASIS_db
#' get_vegplot_tree_si_summary_from_NASIS_db get_vegplot_trhi_from_NASIS_db
#'
#'
#' @param SS fetch data from the currently loaded selected set in NASIS or from the entire local database (default: `TRUE`)
#' @param stringsAsFactors deprecated
#' @param dsn Optional: path to local SQLite database containing NASIS
#' table structure; default: `NULL`
#'
#' @return A named list containing: "vegplot", "vegplotlocation", "vegplotrhi", "vegplotspecies", "vegtransect", "vegtransplantsum", 'vegsiteindexsum', "vegsiteindexdet", and "vegplottext" tables
#'
#' @return A named list containing: "vegplot", "vegplotlocation", "vegplotrhi", "vegplotspecies", "vegtransect", "vegtransplantsum", 'vegsiteindexsum', "vegsiteindexdet", "vegbasalarea", and "vegplottext" tables
#'
#' @export
#'
fetchVegdata <- function(SS=TRUE, stringsAsFactors = NULL, dsn = NULL) {

if (!missing(stringsAsFactors) && is.logical(stringsAsFactors)) {
.Deprecated(msg = sprintf("stringsAsFactors argument is deprecated.\nSetting package option with `NASISDomainsAsFactor(%s)`", stringsAsFactors))
NASISDomainsAsFactor(stringsAsFactors)
}


# check if NASIS local DB instance/ODBC data source is available
.soilDB_test_NASIS_connection(dsn = dsn)

# 1. load data in pieces
site <- get_site_data_from_NASIS_db(SS = SS, dsn = dsn)
vegplot <- get_vegplot_from_NASIS_db(SS = SS, dsn = dsn)
Expand All @@ -41,18 +41,19 @@ fetchVegdata <- function(SS=TRUE, stringsAsFactors = NULL, dsn = NULL) {
vegprodquadrat <- get_vegplot_prodquadrats_from_NASIS_db(SS = SS, dsn = dsn)
vegsiteindexsum <- get_vegplot_tree_si_summary_from_NASIS_db(SS = SS, dsn = dsn)
vegsiteindexdet <- get_vegplot_tree_si_details_from_NASIS_db(SS = SS, dsn = dsn)
vegbasalarea <- get_vegplot_speciesbasalarea_from_NASIS(SS = SS, dsn = dsn)
vegplottext <- get_vegplot_textnote_from_NASIS_db(SS = SS, fixLineEndings = TRUE, dsn = dsn)


# test to see if the selected set is loaded
if (nrow(site) == 0 || nrow(vegplot) == 0) {
message('Selected set is missing either the vegplot, pedon or site table, please load and try again :)')
}

# add ecosite id, corrdate, selection method to vegplot
vegplot <- merge(site[,c("siteiid", "ecositeid", "ecositecorrdate", "siteecositehistory.classifier", "es_selection_method")],
vegplot, by = "siteiid", all.x = TRUE, sort = FALSE)

# done
return(list(
vegplot = vegplot,
Expand All @@ -65,8 +66,9 @@ fetchVegdata <- function(SS=TRUE, stringsAsFactors = NULL, dsn = NULL) {
vegprodquadrat = vegprodquadrat,
vegsiteindexsum = vegsiteindexsum,
vegsiteindexdet = vegsiteindexdet,
vegbasalarea = vegbasalarea,
vegplottext = vegplottext,
site = site
))
}
}

Loading

0 comments on commit dc11538

Please sign in to comment.