From 4480f2a59bb62ebc5fa0fced0032d5487d7c6008 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Mon, 4 Dec 2023 23:01:07 -0600 Subject: [PATCH 1/3] Clone to take care of changing source data --- src/etTran.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/etTran.cpp b/src/etTran.cpp index 0d643cb2..72d1bf58 100644 --- a/src/etTran.cpp +++ b/src/etTran.cpp @@ -2112,6 +2112,8 @@ List etTransParse(List inData, List mv, bool addCmt=false, } 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"); calc.attr("levels") = R_NilValue; From 162a0b10e314d04ff95873466f4676de6cf45d97 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Tue, 5 Dec 2023 05:19:43 -0600 Subject: [PATCH 2/3] Save attributes --- src/etTran.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/etTran.cpp b/src/etTran.cpp index 72d1bf58..8f031589 100644 --- a/src/etTran.cpp +++ b/src/etTran.cpp @@ -451,6 +451,33 @@ bool rxode2parseIsIntegerish(SEXP in) { return as(isIntegerish(in)); } +RObject etTranGetAttrKeep(SEXP in) { + RObject cur = as(in); + std::vector 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(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(ret); +} + //' Event translation for rxode2 //' //' @param inData Data frame to translate @@ -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); 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(calc); @@ -2116,23 +2144,27 @@ List etTransParse(List inData, List mv, bool addCmt=false, 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(calc); } else { curType[0] = IntegerVector::create(3); curType[1] = R_NilValue; + curType[2] = etTranGetAttrKeep(cur); inDataFK[j] = as(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(cur); inDataFKL[j] = curType; } else { From b3630602e291159cae5214eafa4bbe1b0c72b443 Mon Sep 17 00:00:00 2001 From: "Matthew L. Fidler" Date: Tue, 5 Dec 2023 05:44:19 -0600 Subject: [PATCH 3/3] Revise error --- src/etTran.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etTran.cpp b/src/etTran.cpp index 8f031589..d2d9d506 100644 --- a/src/etTran.cpp +++ b/src/etTran.cpp @@ -2168,7 +2168,7 @@ List etTransParse(List inData, List mv, bool addCmt=false, inDataFK[j] = as(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;