Skip to content

Commit

Permalink
Merge pull request #41 from metrumresearchgroup/clone
Browse files Browse the repository at this point in the history
Clone amount in case it is modified
  • Loading branch information
kylebaron authored Sep 24, 2023
2 parents 11304be + efda24d commit 5e17dd6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
)
Expand All @@ -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
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +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
Expand Down
1 change: 1 addition & 0 deletions src/lastdose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> idn;
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-lastdose.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 5e17dd6

Please sign in to comment.