Skip to content

Commit

Permalink
improve imputing zeroe logging
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Dec 12, 2023
1 parent 34e2ffc commit 8b327f3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/methods-Megastudy.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ setMethod('getDTWithImputedZeroes', signature = c('Megastudy', 'VariableMetadata
combinations.dt <- unique(.dt[, -c(weightingVarColName, varSpecColNames), with=FALSE])
combinations.dt[[varSpecEntityIdColName]] <- NULL
combinations.dt <- unique(combinations.dt)
veupathUtils::logWithTime(paste("Found", nrow(combinations.dt), "possible variable value combinations."), verbose)
veupathUtils::logWithTime(paste("Found", nrow(combinations.dt), "existing variable value combinations."), verbose)
entityIds.dt <- unique(.dt[, c(upstreamEntityIdColNames, varSpecEntityIdColName), with=FALSE])


Expand All @@ -309,6 +309,7 @@ setMethod('getDTWithImputedZeroes', signature = c('Megastudy', 'VariableMetadata
add.dt[[weightingVarColName]] <- numeric()
}

veupathUtils::logWithTime(paste("Found", nrow(add.dt), "new combinations of values for", veupathUtils::getColName(variableSpec)), verbose)
return(unique(add.dt))
}

Expand All @@ -317,13 +318,13 @@ setMethod('getDTWithImputedZeroes', signature = c('Megastudy', 'VariableMetadata
merge(x, y, by = c(upstreamEntityIdColNames, varSpecEntityIdColName, weightingVarColName), allow.cartesian=TRUE)
}
.dt2 <- purrr::reduce(dataTablesOfImputedValues, mergeDTsOfImputedValues)
veupathUtils::logWithTime("Finished collapsing imputed values for all variables into one table.", verbose)
veupathUtils::logWithTime(paste("Finished collapsing imputed values for all variables into one table. Added", nrow(.dt2), "total rows."), verbose)

#make impossibly unique ids
.dt2[[varSpecEntityIdColName]] <- apply(.dt2[, c(upstreamEntityIdColNames, varSpecColNames), with=FALSE], 1, digest::digest, algo='md5')
.dt2 <- unique(merge(.dt2, combinations.dt, by=upstreamEntityIdColNames))
.dt <- rbind(.dt, .dt2)
veupathUtils::logWithTime("Added imputed values to table. Finished imputing zeroes.", verbose)
veupathUtils::logWithTime("Added imputed values to existing table. Finished imputing zeroes.", verbose)

return(.dt)
})

0 comments on commit 8b327f3

Please sign in to comment.