}}\preformatted{## rxode2 2.0.14.9000 model named rx_0beb7cac1558d255bf1dcab2e4b4e4cd model (ready).
+\if{html}{\out{
}}\preformatted{## rxode2 2.0.14.9000 model named rx_9140ece6c151a5d4341598adc0f7f3b6 model (ready).
## x$state: depot, center
## x$stateExtra: cp
## x$params: tka, tcl, tv, add.sd, eta.ka, eta.cl, eta.v, rxerr.cp
@@ -336,7 +336,7 @@ compilation model.
mod$simulationIniModel
}\if{html}{\out{
}}\preformatted{## rxode2 2.0.14.9000 model named rx_e62e09f9f1f76ce371e52ab9dcb7c2d3 model (ready).
+\if{html}{\out{
}}\preformatted{## rxode2 2.0.14.9000 model named rx_3696701c79e711bcf4b2c8ac921b3f65 model (ready).
## x$state: depot, center
## x$stateExtra: cp
## x$params: tka, tcl, tv, add.sd, eta.ka, eta.cl, eta.v, rxerr.cp
diff --git a/src/rxode2_df.cpp b/src/rxode2_df.cpp
index 05608ecbc..47043bc31 100644
--- a/src/rxode2_df.cpp
+++ b/src/rxode2_df.cpp
@@ -296,6 +296,9 @@ extern "C" SEXP rxode2_df(int doDose0, int doTBS) {
df[i] = assign_fkeepAttr(j, NumericVector(rx->nr));
} else if (curType == 1) {
df[i] = assign_fkeepAttr(j, StringVector(rx->nr));
+ df[i] = StringVector(rx->nr);
+ } else if (curType == 5) {
+ df[i] = assign_fkeepAttr(j, LogicalVector(rx->nr));
} else {
IntegerVector cur(rx->nr);
if (curType == 2) {
@@ -745,6 +748,10 @@ extern "C" SEXP rxode2_df(int doDose0, int doTBS) {
dfp[ii] = get_fkeep(j, curi + ind->ix[i], ind);
} else if (TYPEOF(tmp) == STRSXP){
SET_STRING_ELT(tmp, ii, get_fkeepChar(j, get_fkeep(j, curi + ind->ix[i], ind)));
+ } else if (TYPEOF(tmp) == LGLSXP) {
+ // Everything here is double
+ dfi = LOGICAL(tmp);
+ dfi[ii] = (int) (get_fkeep(j, curi + ind->ix[i], ind));
} else {
dfi = INTEGER(tmp);
/* if (j == 0) RSprintf("j: %d, %d; %f\n", j, i, get_fkeep(j, curi + i)); */
diff --git a/tests/testthat/test-keep.R b/tests/testthat/test-keep.R
index 82e81d3a5..f6d0bc15c 100644
--- a/tests/testthat/test-keep.R
+++ b/tests/testthat/test-keep.R
@@ -84,7 +84,7 @@ test_that("Make sure the keep gives the right values", {
expect_equal(PK.ev_ref2$AGE, PK.ev_ref2$AGE2)
})
-test_that("rxSolve 'keep' maintains character output (#190)", {
+test_that("rxSolve 'keep' maintains character output (#190/#622)", {
one.cmt <- function() {
ini({
@@ -110,6 +110,7 @@ test_that("rxSolve 'keep' maintains character output (#190)", {
d$oSEX <- d$fSEX
class(d$oSEX) <- c("ordered", "factor")
d$iSEX <- as.integer(d$fSEX)
+ d$lSEX <- as.logical(d$iSEX == 1)
d$dSEX <- d$iSEX + 0.5
library(units)
d$uSEX <- set_units(d$dSEX, kg)
@@ -117,7 +118,7 @@ test_that("rxSolve 'keep' maintains character output (#190)", {
str2lang(e)
})
- sim <- rxSolve(one.cmt, events = d, keep = c("SEX", "fSEX", "iSEX", "dSEX", "oSEX", "uSEX"))
+ sim <- rxSolve(one.cmt, events = d, keep = c("SEX", "fSEX", "iSEX", "dSEX", "oSEX", "uSEX", "lSEX"))
expect_type(sim$SEX, "character")
expect_s3_class(sim$fSEX, "factor")
@@ -126,6 +127,28 @@ test_that("rxSolve 'keep' maintains character output (#190)", {
expect_type(sim$dSEX, "double")
expect_true(inherits(sim$oSEX, "ordered"))
expect_true(inherits(sim$uSEX, "units"))
+ expect_true(is.logical(sim$lSEX))
+
+ d <- nlmixr2data::theo_sd
+ d$SEX <- ifelse(d$ID < 7, "M", "F")
+ d$SEX[4] <- NA_character_
+ d$fSEX <- factor(d$SEX)
+ d$fSEX[4] <- NA_integer_
+ d$iSEX <- as.integer(d$fSEX)
+ d$iSEX[4] <- NA_integer_
+ d$lSEX <- as.logical(d$iSEX == 1)
+ d$lSEX[4] <- NA
+ d$dSEX <- d$iSEX + 0.5
+ d$eSEX <- lapply(d$SEX, function(e) {
+ str2lang(e)
+ })
+
+ sim <- rxSolve(one.cmt, events = d, keep = c("SEX", "fSEX", "iSEX", "dSEX", "lSEX"))
+
+ expect_true(is.na(d$SEX[4]))
+ expect_true(is.na(d$fSEX[4]))
+ expect_true(is.na(d$iSEX[4]))
+ expect_true(is.na(d$lSEX[4]))
expect_error(rxSolve(one.cmt, events = d, keep = c("eSEX")))