diff --git a/DESCRIPTION b/DESCRIPTION index 0196c239..271b95a0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,4 +51,4 @@ Suggests: microbenchmark, cmprsk, glmnet -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 diff --git a/R/DataManagement.R b/R/DataManagement.R index 36834e51..5c4d9029 100644 --- a/R/DataManagement.R +++ b/R/DataManagement.R @@ -835,18 +835,29 @@ loadNewSqlCyclopsDataTimeEffectsDF <- function(object, #' @keywords internal loadNewSqlCyclopsDataTimeInteraction <- function(object, covariateId, - timeEffectMap) { + timeEffectCovId, + timeEffectTimeId) { if (!isInitialized(object)) stop("Object is no longer or improperly initialized.") - if (!all(timeEffectMap$covariateId %in% covariateId)) stop("Invalid covariateId for time effects.") + if (!all(timeEffectCovId %in% covariateId)) stop("Invalid covariateId for time effects.") - timeEffectMap$timeEffectId <- timeEffectMap$timeEffectId - 1 # Cpp start from 0 + timeEffectTimeId <- timeEffectTimeId - 1 # Cpp start from 0 - index <- .loadCyclopsDataTimeInteraction(object, timeEffectMap) + if (!bit64::is.integer64(timeEffectCovId)) { + timeEffectCovId <- bit64::as.integer64(timeEffectCovId) + } + + if (!bit64::is.integer64(timeEffectTimeId)) { + timeEffectTimeId <- bit64::as.integer64(timeEffectTimeId) + } + + index <- .loadCyclopsDataTimeInteraction(object, + timeEffectCovId, + timeEffectTimeId) if (!is.null(object$coefficientNames)) { - timeEffectName <- paste0("x", timeEffectMap$covariateId, ":time", timeEffectMap$timeEffectId + 1) + timeEffectName <- paste0("x", timeEffectCovId, ":time", timeEffectTimeId + 1) object$coefficientNames <- append(object$coefficientNames, timeEffectName) } } diff --git a/R/NewDataConversion.R b/R/NewDataConversion.R index 2f36bd27..53bfd4bd 100644 --- a/R/NewDataConversion.R +++ b/R/NewDataConversion.R @@ -229,7 +229,8 @@ convertToCyclopsData.data.frame <- function(outcomes, if (!all(timeEffectMap$timeEffectId %in% 1:ncol(timeEffects))) stop("Invalid timeEffectId for interaction terms.") loadNewSqlCyclopsDataTimeInteraction(object = dataPtr, covariateId = covariates$covariateId, - timeEffectMap = timeEffectMap) + timeEffectCovId = timeEffectMap$covariateId, + timeEffectTimeId = timeEffectMap$timeEffectId) } } @@ -392,7 +393,8 @@ convertToCyclopsData.tbl_dbi <- function(outcomes, if (!all(timeEffectMap$timeEffectId %in% 1:ncol(timeEffects))) stop("Invalid timeEffectId for interaction terms.") loadNewSqlCyclopsDataTimeInteraction(object = dataPtr, covariateId = covariates$covariateId, - timeEffectMap = timeEffectMap) + timeEffectCovId = timeEffectMap$covariateId, + timeEffectTimeId = timeEffectMap$timeEffectId) } } diff --git a/R/RcppExports.R b/R/RcppExports.R index 54b69aa8..95aed0bd 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -282,8 +282,8 @@ getTimeVector <- function(object) { .Call(`_Cyclops_cyclopsLoadDataTimeEffectsDF`, x, timeEffects) } -.loadCyclopsDataTimeInteraction <- function(x, timeEffectMap) { - .Call(`_Cyclops_cyclopsLoadDataTimeInteraction`, x, timeEffectMap) +.loadCyclopsDataTimeInteraction <- function(x, covariateId, timeEffectId) { + .Call(`_Cyclops_cyclopsLoadDataTimeInteraction`, x, covariateId, timeEffectId) } .appendSqlCyclopsData <- function(x, oStratumId, oRowId, oY, oTime, cRowId, cCovariateId, cCovariateValue) { diff --git a/man/convertToCyclopsData.Rd b/man/convertToCyclopsData.Rd index b6bd5ad0..1b5aad80 100644 --- a/man/convertToCyclopsData.Rd +++ b/man/convertToCyclopsData.Rd @@ -103,11 +103,11 @@ These columns are expected in the timeEffectMap object: } \section{Methods (by class)}{ \itemize{ -\item \code{data.frame}: Convert data from two \code{data.frame} +\item \code{convertToCyclopsData(data.frame)}: Convert data from two \code{data.frame} -\item \code{tbl_dbi}: Convert data from two \code{Andromeda} tables -}} +\item \code{convertToCyclopsData(tbl_dbi)}: Convert data from two \code{Andromeda} tables +}} \examples{ #Convert infert dataset to Cyclops format: covariates <- data.frame(stratumId = rep(infert$stratum, 2), diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 40a2eff4..1b434a10 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -709,14 +709,15 @@ BEGIN_RCPP END_RCPP } // cyclopsLoadDataTimeInteraction -int cyclopsLoadDataTimeInteraction(Environment x, DataFrame timeEffectMap); -RcppExport SEXP _Cyclops_cyclopsLoadDataTimeInteraction(SEXP xSEXP, SEXP timeEffectMapSEXP) { +int cyclopsLoadDataTimeInteraction(Environment x, const std::vector& covariateId, const std::vector& timeEffectId); +RcppExport SEXP _Cyclops_cyclopsLoadDataTimeInteraction(SEXP xSEXP, SEXP covariateIdSEXP, SEXP timeEffectIdSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Environment >::type x(xSEXP); - Rcpp::traits::input_parameter< DataFrame >::type timeEffectMap(timeEffectMapSEXP); - rcpp_result_gen = Rcpp::wrap(cyclopsLoadDataTimeInteraction(x, timeEffectMap)); + Rcpp::traits::input_parameter< const std::vector& >::type covariateId(covariateIdSEXP); + Rcpp::traits::input_parameter< const std::vector& >::type timeEffectId(timeEffectIdSEXP); + rcpp_result_gen = Rcpp::wrap(cyclopsLoadDataTimeInteraction(x, covariateId, timeEffectId)); return rcpp_result_gen; END_RCPP } @@ -840,7 +841,7 @@ static const R_CallMethodDef CallEntries[] = { {"_Cyclops_cyclopsLoadDataMultipleX", (DL_FUNC) &_Cyclops_cyclopsLoadDataMultipleX, 8}, {"_Cyclops_cyclopsLoadDataX", (DL_FUNC) &_Cyclops_cyclopsLoadDataX, 7}, {"_Cyclops_cyclopsLoadDataTimeEffectsDF", (DL_FUNC) &_Cyclops_cyclopsLoadDataTimeEffectsDF, 2}, - {"_Cyclops_cyclopsLoadDataTimeInteraction", (DL_FUNC) &_Cyclops_cyclopsLoadDataTimeInteraction, 2}, + {"_Cyclops_cyclopsLoadDataTimeInteraction", (DL_FUNC) &_Cyclops_cyclopsLoadDataTimeInteraction, 3}, {"_Cyclops_cyclopsAppendSqlData", (DL_FUNC) &_Cyclops_cyclopsAppendSqlData, 8}, {"_Cyclops_cyclopsGetInterceptLabel", (DL_FUNC) &_Cyclops_cyclopsGetInterceptLabel, 1}, {"_Cyclops_cyclopsReadFileData", (DL_FUNC) &_Cyclops_cyclopsReadFileData, 2}, diff --git a/src/RcppModelData.cpp b/src/RcppModelData.cpp index 322cedad..3a58da0a 100644 --- a/src/RcppModelData.cpp +++ b/src/RcppModelData.cpp @@ -640,19 +640,14 @@ int cyclopsLoadDataTimeEffectsDF(Environment x, // [[Rcpp::export(".loadCyclopsDataTimeInteraction")]] int cyclopsLoadDataTimeInteraction(Environment x, - DataFrame timeEffectMap) { + const std::vector& covariateId, + const std::vector& timeEffectId) { using namespace bsccs; XPtr data = parseEnvironmentForPtr(x); - std::vector> tm; - NumericVector cId = timeEffectMap["covariateId"]; - NumericVector tId = timeEffectMap["timeEffectId"]; - for (int i = 0; i < timeEffectMap.nrows(); i++) { - tm.push_back(std::make_pair(cId[i], tId[i])); - } - - return data->loadTimeInteraction(tm); + return data->loadTimeInteraction(reinterpret_cast&>(covariateId), + reinterpret_cast&>(timeEffectId)); } // NOTE: IdType does not get exported into RcppExports, so hard-coded here diff --git a/src/cyclops/ModelData.cpp b/src/cyclops/ModelData.cpp index 432f334e..24ca8fa2 100644 --- a/src/cyclops/ModelData.cpp +++ b/src/cyclops/ModelData.cpp @@ -399,21 +399,23 @@ int ModelData::loadTimeEffectsDF( template int ModelData::loadTimeInteraction( - std::vector>& timeEffectMap) { + const std::vector& oCovariateId, + const std::vector& oTimeEffectId) { int numOfCov = getNumberOfColumns(); int totalNumOfCov = numOfCov; // time effect with baseline covariates - for (auto t : timeEffectMap) { + for (size_t i = 0; i < oCovariateId.size(); i++) { // auto sharedPtrToColumnsVector = make_shared(column.getColumnsVector()); - X.push_back(X.getColumn(t.first).getColumnsVectorPtr(), - X.getColumn(t.first).getDataVectorPtr(), - X.getFormatType(t.first)); + int covId = getColumnIndexByName(oCovariateId[i]); + X.push_back(X.getColumn(covId).getColumnsVectorPtr(), + X.getColumn(covId).getDataVectorPtr(), + X.getFormatType(covId)); X.getColumn(totalNumOfCov++).convertColumnToDense(getNumberOfRows()); int index = getNumberOfColumns() - 1; X.getColumn(index).add_label(index); - mapTimeEffects.addTimeEffectColumn(t.second); + mapTimeEffects.addTimeEffectColumn(oTimeEffectId[i]); } mapTimeEffects.setNumInteraction(totalNumOfCov); diff --git a/src/cyclops/ModelData.h b/src/cyclops/ModelData.h index b620abc9..4802f0a0 100644 --- a/src/cyclops/ModelData.h +++ b/src/cyclops/ModelData.h @@ -232,7 +232,8 @@ class AbstractModelData { ) = 0; virtual int loadTimeInteraction( - std::vector>& timeEffectMap + const std::vector& covariateId, + const std::vector& timeEffectId ) = 0; virtual size_t append( @@ -396,7 +397,8 @@ class ModelData : public AbstractModelData { ); int loadTimeInteraction( - std::vector>& timeEffectMap + const std::vector& covariateId, + const std::vector& timeEffectId ); const int* getPidVector() const;