CRAN status R-CMD-check

pharmr is an R package and toolkit for pharmacometrics. It consists of

pharmr is implemented as an R wrapper to Pharmpy. It provides an R interface to all functions found in the modeling and tools modules (documented here). Each function is also available via the help-function (or ?).

Installation

Install from github

pharmr uses the package reticulate for calling Python from R. When installing pharmr, reticulate will give a prompt to set up the reticulate environment. In order to use pharmr, you need to have Python 3.8 or 3.9. To make reticulate use Python 3.9 in its environment, run the following:

Sys.setenv(RETICULATE_MINICONDA_PYTHON_VERSION="3.9")

Then install pharmr and Pharmpy:

remotes::install_github("pharmpy/pharmr", ref="main")
pharmr::install_pharmpy()

Install from CRAN

pharmr is available on CRAN and can be installed with

install.packages("pharmr")
pharmr::install_pharmpy()

Note that pharmr and Pharmpy are under rapid development and the version on github will be a much more up to date version than the version on CRAN. Check the badges above to see the version numbers for CRAN and github.

Using pharmr

>>> library(pharmr)
>>> model <- read_model("run1.mod")
>>> model$modelfit_results$parameter_estimates
  THETA(1)   THETA(2)   THETA(3) OMEGA(1,1) OMEGA(2,2) SIGMA(1,1)
0.00469555 0.98425800 0.15892000 0.02935080 0.02790600 0.01324100
>>> model$parameters
       name     value  lower    upper    fix
   THETA(1)  0.004693   0.00  1000000  False
   THETA(2)  1.009160   0.00  1000000  False
   THETA(3)  0.100000  -0.99  1000000  False
 OMEGA(1,1)  0.030963   0.00       oo  False
 OMEGA(2,2)  0.031128   0.00       oo  False
 SIGMA(1,1)  0.013086   0.00       oo  False
>>>

A simple example of reading a model, performing a simple transformation, and running the model in NONMEM:

model <- load_example_model('pheno') %>%
  add_peripheral_compartment() %>%
  fit()

Note: If you try to access data frames belonging to a Pharmpy object you often need to reset the index. All functions available in pharmr do this automatically, it is only when you have data frames nested in objects (such as a model object) that you need to do this. An example:

model <- load_example_model('pheno')
residuals <- reset_index(model$modelfit_results$residuals)