Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into test-convertId-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Dec 5, 2023
2 parents 06cc1cf + 78c04c7 commit c6e2276
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
Binary file modified data/rxReservedKeywords.rda
Binary file not shown.
Binary file modified data/rxResidualError.rda
Binary file not shown.
Binary file modified data/rxSyntaxFunctions.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions man/rxode2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/rxode2_df.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)); */
Expand Down
27 changes: 25 additions & 2 deletions tests/testthat/test-keep.R
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -110,14 +110,15 @@ 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)
d$eSEX <- lapply(d$SEX, function(e) {
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")
Expand All @@ -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")))

Expand Down

0 comments on commit c6e2276

Please sign in to comment.