From 208ebadc75e99edb91fb7117903cbf598d941a8d Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Fri, 22 Sep 2023 09:34:05 -0500 Subject: [PATCH 1/3] roxygen update --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a654b69..aba6b70 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: lastdose Type: Package Title: Calculate Time and Amount of Last Dose -Version: 0.4.1 +Version: 0.4.1.9000 Authors@R: c( person("Kyle T", "Baron", email = "kyleb@metrumrg.com", role=c("aut", "cre"), comment=c(ORCID="0000-0001-7252-5656")) ) diff --git a/NEWS.md b/NEWS.md index ec98355..dd17bea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# lastdose (development version) + # lastdose 0.4.1 - Fix bug where comments vector wasn't getting adjusted when `TIME` contained From d5cfec766748de5a1fc85fd5ffc3146b6af70d88 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Fri, 22 Sep 2023 09:38:59 -0500 Subject: [PATCH 2/3] clone amt in case it is modified --- src/lastdose.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lastdose.cpp b/src/lastdose.cpp index 23ab7f3..0a0a7aa 100644 --- a/src/lastdose.cpp +++ b/src/lastdose.cpp @@ -59,6 +59,7 @@ Rcpp::List lastdose_impl(Rcpp::NumericVector id, Rcpp::LogicalVector sort1, Rcpp::LogicalVector comment) { + amt = Rcpp::clone(amt); bool use_comp1 = sort1[0]; bool use_fill = !back_calc[0]; std::vector idn; From efda24d96b49d9f391f572e2aefad525c4d72018 Mon Sep 17 00:00:00 2001 From: Kyle Baron Date: Fri, 22 Sep 2023 09:46:56 -0500 Subject: [PATCH 3/3] news entry --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ tests/testthat/test-lastdose.R | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index aba6b70..9ee089e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,6 @@ BugReports: https://github.com/metrumresearchgroup/lastdose/issues Suggests: testthat, withr Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) Language: en-US diff --git a/NEWS.md b/NEWS.md index dd17bea..31ba998 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # lastdose (development version) +## Bugs Fixed + +- Fixed bug where `amt` was getting modified in source data frame + when it contained missing values (#40, #41). + # lastdose 0.4.1 - Fix bug where comments vector wasn't getting adjusted when `TIME` contained diff --git a/tests/testthat/test-lastdose.R b/tests/testthat/test-lastdose.R index ad6c0c2..8ce3348 100644 --- a/tests/testthat/test-lastdose.R +++ b/tests/testthat/test-lastdose.R @@ -359,3 +359,21 @@ test_that("comments vector is subset for NA time #38 [LSD-TEST-025]", { data <- lastdose(data) expect_equal(data$TAD, c(-1, 0, NA, -1, 0, 0.25)) }) + +test_that("data frame is not modified", { + data <- data.frame( + ID = 1, + AMT = c(0, 1, NA, 0, 0), + TIME = c(1, 2, 3, 4, 5), + EVID = c(0, 1, 0, 0, 0) + ) + data2 <- data.frame( + ID = 1, + AMT = c(0, 1, NA, 0, 0), + TIME = c(1, 2, 3, 4, 5), + EVID = c(0, 1, 0, 0, 0) + ) + expect_identical(data, data2) + ld <- lastdose(data) + expect_identical(data, data2) +})