metrumresearchgroup / TFLGenerator

The TFL generator meta repository. This includes the GUI and TFL R packages as submodules and manages the shiny application deliverable.
0 stars 0 forks source link

calling functions from various packages #26

Open narayanana opened 5 years ago

narayanana commented 5 years ago

Hi .. How do I call function like AUC from metrumrg package into TFL Generator?

dpolhamus commented 5 years ago

Hi Naren,

metrumrg is loaded, so you should just be able to call AUC. Exactly how you call it in context of the app is a little tricky, something like auc_partial from PKPDmisc is much better suited for a dplyr type workflow.

The problem is, we don't explicitly load PKPDmisc in the TFL generator. So, do something like this:

  library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.4.4
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
  library(PKPDmisc)
#> Warning: package 'PKPDmisc' was built under R version 3.4.3
  library(metrumrg)
#> Loading required package: reshape
#> 
#> Attaching package: 'reshape'
#> The following object is masked from 'package:dplyr':
#> 
#>     rename
#> Loading required package: lattice
#> Loading required package: XML
#> Warning: package 'XML' was built under R version 3.4.4
#> Loading required package: MASS
#> Warning: package 'MASS' was built under R version 3.4.4
#> 
#> Attaching package: 'MASS'
#> The following object is masked from 'package:dplyr':
#> 
#>     select
#> Loading required package: grid
#> metrumrg 5.57
#> enter "?metrumrg" for help
#> 
#> Attaching package: 'metrumrg'
#> The following objects are masked from 'package:dplyr':
#> 
#>     contains, first, last, nth
  data(Theoph)

  Theoph %>% 
    group_by(Subject) %>%
    mutate(AUC_0_inf=PKPDmisc::auc_partial(Time, conc)) %>%
    head
#> Warning: package 'bindrcpp' was built under R version 3.4.4
#> # A tibble: 6 x 6
#> # Groups:   Subject [1]
#>   Subject    Wt  Dose  Time  conc AUC_0_inf
#>   <ord>   <dbl> <dbl> <dbl> <dbl>     <dbl>
#> 1 1        79.6  4.02 0      0.74      149.
#> 2 1        79.6  4.02 0.25   2.84      149.
#> 3 1        79.6  4.02 0.570  6.57      149.
#> 4 1        79.6  4.02 1.12  10.5       149.
#> 5 1        79.6  4.02 2.02   9.66      149.
#> 6 1        79.6  4.02 3.82   8.58      149.

  Theoph %>%
    left_join(
      Theoph %>% metrumrg::AUC(time="Time", id="Subject", dv="conc")
    ) %>% head
#> Joining, by = "Subject"
#>   Subject   Wt Dose Time  conc     AUC
#> 1       1 79.6 4.02 0.00  0.74 148.923
#> 2       1 79.6 4.02 0.25  2.84 148.923
#> 3       1 79.6 4.02 0.57  6.57 148.923
#> 4       1 79.6 4.02 1.12 10.50 148.923
#> 5       1 79.6 4.02 2.02  9.66 148.923
#> 6       1 79.6 4.02 3.82  8.58 148.923

Created on 2018-10-09 by the reprex package (v0.2.1)

narayanana commented 5 years ago

Thanks for the tips