billdenney / pknca

An R package is designed to perform all noncompartmental analysis (NCA) calculations for pharmacokinetic (PK) data.
http://billdenney.github.io/pknca/
GNU Affero General Public License v3.0
70 stars 23 forks source link

argument "fun_linear" is missing, with no default #311

Closed joybaker1 closed 3 months ago

joybaker1 commented 3 months ago

I don't understand what this error means. I made an easy dataset to reflect the same error message I had with my larger dataset. I have updated the pknca to the latest. Thanks

Error message:

Caused by error in auc_integrate(): ! argument "fun_linear" is missing, with no default Run rlang::last_trace() to see where the error occurred.

rlang::last_trace() <error/dplyr:::mutate_error> Error in mutate(): i In argument: AUC = pk.calc.auxc(conc = DV, time = TAFD_AD, interval = c(0, 8), method = "lin up/log down"). i In group 1: ID = 1. Caused by error in auc_integrate(): ! argument "fun_linear" is missing, with no default

Backtrace: x

  1. +-df %>% group_by(ID) %>% ...
  2. +-dplyr::mutate(...)
  3. +-dplyr:::mutate.data.frame(...)
  4. | -dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  5. | +-base::withCallingHandlers(...)
  6. | -dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  7. | -mask$eval_all_mutate(quo)
  8. | -dplyr (local) eval()
  9. -PKNCA::pk.calc.auxc(...)
  10. -PKNCA:::auc_integrate(...) Run rlang::last_trace(drop = FALSE) to see 3 hidden frames.
df <- data.frame(TAFD_AD=c(0,0.25,2,4,6,8,        0,0.25,2,4,6,8),
                 DV=c(0,0.1,0.6,0.5,0.2,0.1,0,0.2,0.7,0.4,0.3,0.1),
                 ID=c(1,1,1,1,1,1,2,2,2,2,2,2)
)
df
df <- df %>%
  group_by(ID) %>%
  mutate(AUC = pk.calc.auxc(
    conc = DV,
    time = TAFD_AD,
    interval = c(0, 8),
    method="lin up/log down")
  )
billdenney commented 3 months ago

pk.calc.auxc() is not usually the function you want to call. You probably want to use pk.calc.auc.last() based on your data.

Depending on exactly what you're doing, though, you probably want to do something like:

library(tidyverse)
library(PKNCA)
#> 
#> Attaching package: 'PKNCA'
#> The following object is masked from 'package:stats':
#> 
#>     filter

df <-
  data.frame(
    TAFD_AD=c(0,0.25,2,4,6,8,
              0,0.25,2,4,6,8),
    DV= c(0,0.1,0.6,0.5,0.2,0.1,
          0,0.2,0.7,0.4,0.3,0.1),
    ID=c(1,1,1,1,1,1,
         2,2,2,2,2,2)
  )

o_conc <- PKNCAconc(df, DV~TAFD_AD|ID)
o_data <- PKNCAdata(o_conc, intervals = data.frame(start = 0, end = 8, auclast = TRUE))
o_nca <- pk.nca(o_data)
#> No dose information provided, calculations requiring dose will return NA.
summary(o_nca)
#>  start end N     auclast
#>      0   8 2 2.80 [7.04]
#> 
#> Caption: auclast: geometric mean and geometric coefficient of variation; N: number of subjects
as.data.frame(o_nca)
#> # A tibble: 2 × 6
#>      ID start   end PPTESTCD PPORRES exclude
#>   <dbl> <dbl> <dbl> <chr>      <dbl> <chr>  
#> 1     1     0     8 auclast     2.67 <NA>   
#> 2     2     0     8 auclast     2.94 <NA>

# Or, if you're doing this with simulations and need many NCA calculations and
# speed is vitally important:

df_calc <- 
  df |>
  group_by(ID) |>
  summarize(AUC = pk.calc.auc.last(
    conc = DV,
    time = TAFD_AD,
    interval = c(0, 8),
    method="lin up/log down")
  )
df_calc
#> # A tibble: 2 × 2
#>      ID   AUC
#>   <dbl> <dbl>
#> 1     1  2.67
#> 2     2  2.94

Created on 2024-07-31 with reprex v2.1.0