Skip to content

Commit

Permalink
[dims] code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jun 29, 2024
1 parent bad89ff commit 677c27a
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,31 @@ SEXP dims_to_df(Rcpp::IntegerVector rows, Rcpp::CharacterVector cols, Rcpp::Null
SET_VECTOR_ELT(df, i, Rcpp::CharacterVector(nn, NA_STRING));
}

if (has_filled && fill) {

std::vector<std::string> flld = Rcpp::as<std::vector<std::string>>(filled.get());
std::unordered_set<std::string> flls(flld.begin(), flld.end());

// with has_filled we always have to run this loop
for (size_t i = 0; i < kk; ++i) {
Rcpp::CharacterVector cvec = Rcpp::as<Rcpp::CharacterVector>(df[i]);
std::string coli = Rcpp::as<std::string>(cols[i]);
for (size_t j = 0; j < nn; ++j) {
std::string cell = coli + std::to_string(rows[j]);
if (has_cell(cell, flls))
cvec[j] = coli + std::to_string(rows[j]);
// else cvec[j] = "";
if (fill) {
if (has_filled) {

std::vector<std::string> flld = Rcpp::as<std::vector<std::string>>(filled.get());
std::unordered_set<std::string> flls(flld.begin(), flld.end());

// with has_filled we always have to run this loop
for (size_t i = 0; i < kk; ++i) {
Rcpp::CharacterVector cvec = Rcpp::as<Rcpp::CharacterVector>(df[i]);
std::string coli = Rcpp::as<std::string>(cols[i]);
for (size_t j = 0; j < nn; ++j) {
std::string cell = coli + std::to_string(rows[j]);
if (has_cell(cell, flls))
cvec[j] = cell;
}
}
}

} else if (fill) { // insert cells into data frame
} else { // insert cells into data frame

for (size_t i = 0; i < kk; ++i) {
Rcpp::CharacterVector cvec = Rcpp::as<Rcpp::CharacterVector>(df[i]);
std::string coli = Rcpp::as<std::string>(cols[i]);
for (size_t j = 0; j < nn; ++j) {
cvec[j] = coli + std::to_string(rows[j]);
for (size_t i = 0; i < kk; ++i) {
Rcpp::CharacterVector cvec = Rcpp::as<Rcpp::CharacterVector>(df[i]);
std::string coli = Rcpp::as<std::string>(cols[i]);
for (size_t j = 0; j < nn; ++j) {
cvec[j] = coli + std::to_string(rows[j]);
}
}
}

Expand Down

0 comments on commit 677c27a

Please sign in to comment.