From e0a07925a921a2b576a6705c13ac116cc1bd9ffa Mon Sep 17 00:00:00 2001 From: Josh Yamamoto Date: Fri, 28 Jun 2024 09:41:21 -0500 Subject: [PATCH] allowing totals to work but stepping back from rowvar & colvar --- R/modGBchng.R | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/R/modGBchng.R b/R/modGBchng.R index 050f8c6f..6c929258 100644 --- a/R/modGBchng.R +++ b/R/modGBchng.R @@ -267,7 +267,7 @@ modGBchng <- function(GBpopdat, parameters <- FALSE returnlst <- list() rawdata <- TRUE - #colvar <- NULL + colvar <- NULL ## Set global variables ONEUNIT=n.total=n.strata=strwt=TOTAL= @@ -502,43 +502,38 @@ modGBchng <- function(GBpopdat, setkeyv(condf, c(cuniqueid, condid)) groupby.qry <- paste0(toString(paste0("sccm.", strunitvars)), ", c.", cuniqueid, ", c.", condid) - prev_rowvar <- paste0("PREV_", rowvar) - rowvar_keep <- NULL if (rowvar != "TOTAL") { - + select.qry <- paste0(groupby.qry, ", pcond.", rowvar, " AS ", prev_rowvar) if (colvar != "NONE") { - - select.qry <- paste0(groupby.qry, ", c.", rowvar, " AS ", rowvar, ", c.", colvar, " AS ", colvar) - + select.qry <- paste0(select.qry, ", c.", colvar, " AS ", colvar) } else { - select.qry <- paste0(groupby.qry, ", pcond.", rowvar, " AS ", prev_rowvar) - ## Copy rowvar information to colvar colvar <- rowvar - colvarnm <- rowvarnm + colvarnm <- rowvarnm uniquecol <- copy(uniquerow) title.colvar <- title.rowvar - - rowvar_keep <- rowvar - - if (!is.null(row.orderby)) col.orderby <- row.orderby - + if (!is.null(row.orderby)) { + col.orderby <- row.orderby + } select.qry <- paste0(select.qry, ", c.", rowvar) - + ## Add prefix to rowvar names(uniquerow) <- paste0("PREV_", names(uniquerow)) rowvar <- prev_rowvar rowvarnm <- paste0("PREV_", rowvarnm) - if (!is.null(row.orderby)) row.orderby <- paste0("PREV_", row.orderby) - + if (!is.null(row.orderby)) { + row.orderby <- paste0("PREV_", row.orderby) + } + ## Get group variable for cell values grpvar <- c(rowvar, colvar) } + } else { - select.qry <- groupby.qry + select.qry <- groupby.qry } if (chngtype == "annual") { @@ -564,11 +559,7 @@ modGBchng <- function(GBpopdat, "\nGROUP BY ", groupby.qry) if (rowvar != "TOTAL") { - if (!is.null(rowvar_keep)) { - condf_chng.qry <- paste0(condf_chng.qry, ", ", rowvar, ", c.", colvar) - } else { - condf_chng.qry <- paste0(condf_chng.qry, ", c.", rowvar, ", c.", colvar) - } + condf_chng.qry <- paste0(condf_chng.qry, ", ", rowvar, ", c.", colvar) } message(condf_chng.qry)