Skip to content

Commit

Permalink
Merge pull request #34 from joshyam-k/master
Browse files Browse the repository at this point in the history
fix modGBchng bugs
  • Loading branch information
joshyam-k authored Jun 28, 2024
2 parents ea0012e + e0a0792 commit 118b89c
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions R/modGBchng.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,46 +501,39 @@ modGBchng <- function(GBpopdat,
setkeyv(condx, c(cuniqueid, condid))
setkeyv(condf, c(cuniqueid, condid))


# if (rowvar == "TOTAL" || colvar == "NONE") {
# stop("must include a rowvar and a colvar for area change estimates")
# }

# groupby.qry <- paste0("c.", cuniqueid, ", c.", condid)

groupby.qry <- paste0(toString(paste0("sccm.", strunitvars)), ", c.", cuniqueid, ", c.", condid)
# groupby.qry <- paste0(toString(strunitvars), ", "c.", cuniqueid)
prev_rowvar <- paste0("PREV_", rowvar)

if (rowvar != "TOTAL") {
select.qry <- paste0(groupby.qry, ", pcond.", rowvar, " AS ", prev_rowvar)
if (colvar != "NONE") {
select.qry <- paste0(select.qry, ", c.", colvar, " AS ", colvar)
} else {

## Copy rowvar information to colvar
colvar <- rowvar
colvarnm <- rowvarnm
colvarnm <- rowvarnm
uniquecol <- copy(uniquerow)
title.colvar <- title.rowvar
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)
}

## Get group variable for cell values
grpvar <- c(rowvar, colvar)
}
# } else {
# select.qry <- groupby.qry

} else {
select.qry <- groupby.qry
}

if (chngtype == "annual") {
Expand All @@ -564,16 +557,6 @@ modGBchng <- function(GBpopdat,
AND COALESCE(c.COND_NONSAMPLE_REASN_CD, 0) = 0
AND COALESCE(pcond.COND_NONSAMPLE_REASN_CD, 0) = 0",
"\nGROUP BY ", groupby.qry)

# condf_chng.qry <- paste0(condf_chng.qry,
# "\nFROM condf c",
# "\nJOIN condf pcond ON (pcond.PLT_CN = c.PREV_PLT_CN)",
# "\nJOIN condx sccm ON (sccm.plt_cn = c.plt_cn
# AND sccm.prev_plt_cn = pcond.plt_cn
# AND sccm.condid = c.condid
# AND sccm.prevcond = pcond.condid)",
# "\nGROUP BY ", groupby.qry)


if (rowvar != "TOTAL") {
condf_chng.qry <- paste0(condf_chng.qry, ", ", rowvar, ", c.", colvar)
Expand All @@ -589,7 +572,7 @@ modGBchng <- function(GBpopdat,

if (length(unitvars) == 2) {
cdomdat[, (unitvar) := paste(cdomdat[[unitvars[1]]], cdomdat[[unitvars[2]]], sep="-")]
strunitvars <- c(unitvar, strvar)
strunitvars <- c(unitvar, strvar)
}

} else { ## cdomdat
Expand Down

0 comments on commit 118b89c

Please sign in to comment.