Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lastdose appears to have a side effect of changing AMT column in data frame it is ran on #40

Closed
andersone1 opened this issue Sep 13, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@andersone1
Copy link

library(tidyverse)

pk <- 
  Theoph %>% 
  transmute(
    ID = dense_rank(Subject),
    WTBL = Wt,
    DOSE = Dose,
    TIME = Time,
    DV = conc,
    EVID = 0
  ) 

dosing <-
  pk %>%
  distinct(ID, DOSE, TIME, WTBL) %>%
  mutate(EVID = 1, AMT = DOSE)

pk$AMT <- NA_real_
  
nm_1 <-
  bind_rows(pk, dosing) %>%
  arrange(ID, TIME) %>% 
  as_tibble()

# nm_1 has NA AMT (which is OK)
head(nm_1$AMT) # NA  4 NA  4 NA  4

# Create nm_2
nm_2 <- lastdose::lastdose(nm_1, include_tafd = TRUE)

# nm_2 has new AMT (which is OK)
head(nm_2$AMT) #  0 4 0 4 0 4

# nm_1 has new AMT (not OK?)
head(nm_1$AMT) #  0 4 0 4 0 4

@kylebaron
Copy link
Collaborator

Reproducing this:

library(tidyverse)

pk <- 
  Theoph %>% 
  transmute(
    ID = dense_rank(Subject),
    WTBL = Wt,
    DOSE = Dose,
    TIME = Time,
    DV = conc,
    EVID = 0
  ) 

dosing <-
  pk %>%
  distinct(ID, DOSE, TIME, WTBL) %>%
  mutate(EVID = 1, AMT = DOSE)

pk$AMT <- NA_real_

nm_1 <-
  bind_rows(pk, dosing) %>%
  arrange(ID, TIME) %>% 
  as_tibble()

# nm_1 has NA AMT (which is OK)
head(nm_1$AMT) # NA  4 NA  4 NA  4
#> [1] NA  4 NA  4 NA  4

# Create nm_2
nm_2 <- lastdose::lastdose(nm_1, include_tafd = TRUE)

# nm_2 has new AMT (which is OK)
head(nm_2$AMT) #  0 4 0 4 0 4
#> [1] 0 4 0 4 0 4

# nm_1 has new AMT (not OK?)
head(nm_1$AMT) #  0 4 0 4 0 4
#> [1] 0 4 0 4 0 4

Created on 2023-09-22 with reprex v2.0.2

@kylebaron
Copy link
Collaborator

kylebaron commented Sep 22, 2023

This is now fixed with d5cfec7

library(tidyverse)

pk <-
  Theoph %>%
  transmute(
    ID = dense_rank(Subject),
    WTBL = Wt,
    DOSE = Dose,
    TIME = Time,
    DV = conc,
    EVID = 0
  )

dosing <-
  pk %>%
  distinct(ID, DOSE, TIME, WTBL) %>%
  mutate(EVID = 1, AMT = DOSE)

pk$AMT <- NA_real_

nm_1 <-
  bind_rows(pk, dosing) %>%
  arrange(ID, TIME) %>%
  as_tibble()

# nm_1 has NA AMT (which is OK)
head(nm_1$AMT) # NA  4 NA  4 NA  4
#> [1] NA  4 NA  4 NA  4

# Create nm_2
nm_2 <- lastdose::lastdose(nm_1, include_tafd = TRUE)

# nm_2 has same AMT
head(nm_2$AMT) #  0 4 0 4 0 4
#> [1] NA  4 NA  4 NA  4

# nm_1 has same AMT
head(nm_1$AMT) #  0 4 0 4 0 4
#> [1] NA  4 NA  4 NA  4

Created on 2023-09-22 with reprex v2.0.2

@andersone1
Copy link
Author

@kylebaron Will this fix be released to a new version that will make it MPN?

@kylebaron
Copy link
Collaborator

Hi @andersone1 - we can release it.

@kylebaron kylebaron mentioned this issue Nov 27, 2023
@andersone1
Copy link
Author

Sounds good @kylebaron . I am OK closing this issue if you are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants