Skip to content

Commit

Permalink
allowing totals to work but stepping back from rowvar & colvar
Browse files Browse the repository at this point in the history
  • Loading branch information
joshyam-k committed Jun 28, 2024
1 parent ed5009b commit e0a0792
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions R/modGBchng.R
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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") {
Expand All @@ -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)

Expand Down

0 comments on commit e0a0792

Please sign in to comment.