Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Clone to take care of changing source data #79

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/etTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,33 @@ bool rxode2parseIsIntegerish(SEXP in) {
return as<bool>(isIntegerish(in));
}

RObject etTranGetAttrKeep(SEXP in) {
RObject cur = as<RObject>(in);
std::vector<std::string> attr = cur.attributeNames();
if (cur.hasAttribute("levels")) {
List ret(attr.size()-1);
CharacterVector retN(attr.size()-1);
unsigned int j = 0;
for (unsigned int i = 0; i < attr.size(); ++i) {
if (attr[i] != "levels") {
retN[j] = attr[i];
ret[j] = cur.attr(attr[i]);
j++;
}
}
ret.attr("names") = retN;
return as<RObject>(ret);
}
List ret(attr.size());
CharacterVector retN(attr.size());
for (unsigned int i = 0; i < attr.size(); ++i) {
retN[i] = attr[i];
ret[i] = cur.attr(attr[i]);
}
ret.attr("names") = retN;
return as<RObject>(ret);
}

//' Event translation for rxode2
//'
//' @param inData Data frame to translate
Expand Down Expand Up @@ -2100,41 +2127,48 @@ List etTransParse(List inData, List mv, bool addCmt=false,
for (j = 0; j < (int)(keepCol.size()); j++){
SEXP cur = inData[keepCol[j]];
RObject calc;
List curType(2);
List curType(3);
if (TYPEOF(cur) == STRSXP){
calc = convertId_(cur);
curType[0] = IntegerVector::create(1);
curType[1] = calc.attr("levels");
curType[2] = etTranGetAttrKeep(cur);
calc.attr("levels") = R_NilValue;
calc.attr("class") = R_NilValue;
inDataFK[j] = as<NumericVector>(calc);
inDataFKL[j] = curType;
} else if (TYPEOF(cur) == INTSXP){
calc = cur;
if (calc.hasAttribute("levels")) {
// need to check type
calc = clone(cur); // make sure they don't affect changes
curType[0] = IntegerVector::create(2);
curType[1] = calc.attr("levels");
curType[2] = etTranGetAttrKeep(cur);
calc.attr("levels") = R_NilValue;
calc.attr("class") = R_NilValue;
inDataFK[j] = as<NumericVector>(calc);
} else {
curType[0] = IntegerVector::create(3);
curType[1] = R_NilValue;
curType[2] = etTranGetAttrKeep(cur);
inDataFK[j] = as<NumericVector>(calc);
}
inDataFKL[j] = curType;
} else if (TYPEOF(cur) == REALSXP) {
curType[0] = IntegerVector::create(4);
curType[1] = R_NilValue;
curType[2] = etTranGetAttrKeep(cur);
inDataFK[j] = cur;
inDataFKL[j] = curType;
} else if (TYPEOF(cur) == LGLSXP) {
curType[0] = IntegerVector::create(5);
curType[1] = R_NilValue;
curType[2] = etTranGetAttrKeep(cur);
inDataFK[j] = as<NumericVector>(cur);
inDataFKL[j] = curType;
} else {
stop(_("the columns that are kept must be either a logical, string, a factor, an integer number, or a real number"));
stop(_("the columns that are kept must be either an underlying logical, string, factor, integer number, or real number"));
}
}
int maxItemsPerId = 0;
Expand Down
Loading