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

Commit

Permalink
Save attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Dec 5, 2023
1 parent 4480f2a commit 162a0b1
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion 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++;

Check warning on line 465 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L454-L465

Added lines #L454 - L465 were not covered by tests
}
}
ret.attr("names") = retN;
return as<RObject>(ret);

Check warning on line 469 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L468-L469

Added lines #L468 - L469 were not covered by tests
}
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]);

Check warning on line 475 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L471-L475

Added lines #L471 - L475 were not covered by tests
}
ret.attr("names") = retN;
return as<RObject>(ret);

Check warning on line 478 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L477-L478

Added lines #L477 - L478 were not covered by tests
}

//' Event translation for rxode2
//'
//' @param inData Data frame to translate
Expand Down Expand Up @@ -2100,11 +2127,12 @@ 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);

Check warning on line 2130 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2130

Added line #L2130 was not covered by tests
if (TYPEOF(cur) == STRSXP){
calc = convertId_(cur);
curType[0] = IntegerVector::create(1);
curType[1] = calc.attr("levels");
curType[2] = etTranGetAttrKeep(cur);

Check warning on line 2135 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2135

Added line #L2135 was not covered by tests
calc.attr("levels") = R_NilValue;
calc.attr("class") = R_NilValue;
inDataFK[j] = as<NumericVector>(calc);
Expand All @@ -2116,23 +2144,27 @@ List etTransParse(List inData, List mv, bool addCmt=false,
calc = clone(cur); // make sure they don't affect changes

Check warning on line 2144 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2144

Added line #L2144 was not covered by tests
curType[0] = IntegerVector::create(2);
curType[1] = calc.attr("levels");
curType[2] = etTranGetAttrKeep(cur);

Check warning on line 2147 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2147

Added line #L2147 was not covered by tests
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);

Check warning on line 2154 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2154

Added line #L2154 was not covered by tests
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);

Check warning on line 2161 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2161

Added line #L2161 was not covered by tests
inDataFK[j] = cur;
inDataFKL[j] = curType;
} else if (TYPEOF(cur) == LGLSXP) {
curType[0] = IntegerVector::create(5);
curType[1] = R_NilValue;
curType[2] = etTranGetAttrKeep(cur);

Check warning on line 2167 in src/etTran.cpp

View check run for this annotation

Codecov / codecov/patch

src/etTran.cpp#L2167

Added line #L2167 was not covered by tests
inDataFK[j] = as<NumericVector>(cur);
inDataFKL[j] = curType;
} else {
Expand Down

0 comments on commit 162a0b1

Please sign in to comment.