stanpumpR, a PK/PD simulation program Copyright 2019-2026 Steven L. Shafer and contributors, [email protected]. Released under the MIT License; see LICENSE.md.
stanpumpR is open-source software for pharmacokinetic / pharmacodynamic simulation. It is intended to make pharmacokinetics accessible to facilitate perioperative patient care, teaching, and research. It is released under the MIT License: anyone may use, copy, modify and redistribute it, including commercially, provided the copyright and licence notice is kept with it.
stanpumpR is an advisory and teaching tool. It does not control drug delivery, it has not been reviewed or cleared by any regulatory agency, and how its predictions are applied to an individual patient is a matter of clinical judgement. It is provided as is, without warranty of any kind; see the licence.
STANPUMP, a portmanteau of "Stanford" and "Pump", was developed in the Stanski/Shafer laboratory at Stanford University from 1987 through 1997. STANPUMP was one of many programs developed to control the delivery of intravenous anesthetics using pharmacokinetic principles. At that time there was an active exchange of concepts and algorithms among the authors. Significant contributors to this effort were Schüttler and Schwilden at the University of Bonn (CATIA), Ausems and Hug at the University of Leiden (TIAC), Reves and Alvis at the University of Alabama (CACI), Jacobs and Reves at Duke University (CACI II), Coetzee and Pina at Stellenbosch University (STELPUMP), and De Smet and Struys at the University of Ghent (RUGLOOP). This history was recently reviewed by Struys and colleagues: The History of Target-Controlled Infusion. Anesth Analg. 2016;122:56-69.
STANPUMP was distributed freely: anyone could copy and share its source and executable code, though not sell it. The STANPUMP pharmacokinetic engine was incorporated into many of the commercially available target-controlled infusion devices, where it is still used today.
stanpumpR uses almost none of the original STANPUMP code. However, conceptually it is identical: an open-source program to make complex pharmacokinetic algorithms available to support patient care, teaching, and research. The major difference is that STANPUMP was interfaced to several pumps and controlled drug administration based on pharmacokinetics. stanpumpR has no such ability. It is simply a web-based simulator, programmed in R, that uses the Shiny package to simulate the expected concentration of a drug from any dosing regimen. In the past year stanpumpR has grown from a package focused on anesthesia to a package with nearly all drug classes and well over 100 drugs. The library includes intravenous, oral, subcutaneous, and inhaled routes of delivery. The package understands the effect of pharmacogenetics and drug-drug interactions on CYP metabolism. The package understands the formation of active metabolites, and the conversion of oral prodrugs into active moieties via first-pass and systemic hepatic metabolism.
stanpumpR also has a program to extract pharmacokinetics from published papers and permit generalized simulations using the extracted values.
The pharmacokinetic algorithms in stanpumpR are based on mathematics, supported primarily by the peer-reviewed literature. The only exceptions are cases where the peer-reviewed literature is absent, in which case the pharmacokinetics are taken from either FDA or EMA monographs. If you ask, "I have a patient with Crohn's disease. How will that affect phenytoin metabolism?", stanpumpR won't know. However, let's say a study documented reduced absorption of phenytoin in patients with Crohn's disease. I could upload that paper, extract the mathematical model, and have stanpumpR include a checkbox for Crohn's disease if phenytoin is simulated.
That literature reaches stanpumpR through Lane Medical Library at Stanford University: its licensed collections for the current journals, and its document delivery service for the older and more obscure papers, some of which are not online anywhere. A model is only as good as the paper it was read from, and in this project the paper is almost always read in full rather than from its abstract, which is possible only because Lane makes it possible. Stanford's library resources made stanpumpR possible. I am deeply grateful to Stanford and to Lane Medical Library for the resources they provide to Stanford faculty, which make projects like stanpumpR possible.
What the papers say is public; the papers themselves are not. Each one is read and condensed into a digest — what the model is, which numbers were read and from which table, what the paper leaves open, and what could not be verified — and those digests are in this repository, in papers/digests/, one per paper. The journal articles they were made from are copyrighted, so I keep those privately and they are not distributed; the FDA prescribing information is a public document, so those PDFs are in the repository, in papers/labels/. The digests hold facts and paraphrase rather than copies, which is what makes publishing them possible, and they are what the models are actually built from: when a drug's parameters are questioned, the digest is the record of where each number came from. They are audited regularly for accuracy by large language models — Claude, Gemini and ChatGPT — which is how transcription errors and misread tables are caught.
I want to give a shout-out to Claude Code, which is my primary programming engine. Most of the expansion of stanpumpR in the past year has been implemented by Claude Code (Opus 5.5 or Fable 5.1). Claude Code can interpret the PK of an uploaded manuscript. Claude Code rigorously inspects each PK paper I upload, including simulations of the graphs to see if the PK actually describe the data. It also checks that the reported PK parameters are internally consistent (e.g., does Clearance = Dose / AUC after an intravenous dose, or CL/F = Dose / AUC after an oral dose, where F is the bioavailability, and are the half-lives correctly calculated from the volumes and clearances for multicompartmental models).
I also want to acknowledge the role of ChatGPT (Sol 6.1) and Gemini (version 4, Argon) in providing adversarial review. Almost every day ChatGPT and Gemini conduct adversarial reviews of the code and of the manuscript parsing. Almost weekly ChatGPT "Daybreak Blue" audits the code and the deployed app for exploitable security flaws. The audit includes execution in all Chromium and WebKit browsers, as well as execution on Android and iOS.
I am grateful to Richard Hooijmaijers, Matthew Fidler, Bill Denney and Kiranmayi Vedantham, who maintain nlmixr2lib, A Model Library for 'nlmixr2'. nlmixr2lib transcribes several thousand published population pharmacokinetic and pharmacodynamic models and makes them public. stanpumpR uses it in two ways. First, it is an independent reading of the papers stanpumpR has also read: comparing the two, number by number, has caught and corrected errors in stanpumpR's models. Second, it is a guide to the literature, leading stanpumpR to the papers behind a dozen of its drug models so far, and to many more on the list still to be built. stanpumpR uses nlmixr2lib's data only, never its code, and every number is read in the original paper before it enters a model (see docs/nlmixr2lib/README.md). Their work is a large part of how stanpumpR can bring published pharmacokinetics to the bedside.
As an open-source project, I previously permitted interested individuals to edit the repository directly. I no longer permit this because it presents a security risk. A malicious actor could potentially upload compromised code and use stanpumpR to infect hospital computers. Only two individuals can change the code directly: Dean Attali (an exceptional R / JS programmer) and me. Dean still programs himself. I only use Claude Code. Anyone may still propose a change as a pull request, which one of us reviews before it is merged (see .github/CONTRIBUTING.md). If there are features you wish to incorporate into stanpumpR, please send me an email ([email protected]). I'll likely be able to add them.
In 2026 stanpumpR gained an engine for the inhaled anesthetics. Its structure and parameters follow GasMan®, the model of inhaled anesthetic uptake and distribution developed by James H. Philip at Brigham and Women's Hospital and Harvard Medical School, which has taught a generation of anesthesiologists how these drugs behave. Richard H. Epstein of the University of Miami validated the stanpumpR engine against GasMan, running the comparison scenarios and tracing each disagreement to its cause; that record is in inst/validation/VALIDATION.md. The places where stanpumpR deliberately departs from GasMan are listed in the user's guide.
It is hoped that stanpumpR will encourage device manufacturers to develop the next generation of drug delivery systems and anesthesia information management systems. Companies are welcome to build on stanpumpR under the terms of the MIT License. As a courtesy, Dr. Shafer would be glad to hear from them.
stanpumpR is a collaborative research project. Individuals interested in adding drugs, pharmacokinetic data sets, or new algorithms to stanpumpR are encouraged to contact Dr. Shafer. It is hoped that eventually each drug in the stanpumpR library will be maintained by an investigator, who will assume responsibility for keeping the pharmacokinetics as up-to-date as possible. See docs/adding-a-drug.md for the technical steps.
Since October 2026 the library also has an agentic AI step to keep its pharmacokinetics state of the art. A scheduled Claude Code routine, running in the cloud, searches PubMed every week for new pharmacokinetic studies of every drug in the library, screens them, and emails the maintainer the promising ones with its own assessment of what each would add. The maintainer decides what to incorporate; the routine changes no code. See docs/literature-watch.md.
stanpumpR is open source, under the MIT License, which means anyone may use, copy, modify and redistribute it, including commercially, provided the copyright and license notice is kept with it.
docs/architecture.md— how the app is put together: the reactive pipeline, the PK/PD engine, and the file layout.docs/adding-a-drug.md— the touch points for contributing a new drug, including its help page.docs/users-guide.md— a draft user's guide written from the code.docs/literature-watch.md— the weekly AI literature watch that searches PubMed for new pharmacokinetic studies of the library's drugs and emails the maintainer the promising ones.- stanpumpr.io/api — the Simulation API: send a dose table,
covariates and a duration (over HTTP from any language, or from R) and get the concentrations
back as JSON, CSV, Excel or XML. The page is rendered from
inst/apidocs/api.md. docs/tci-api.md— the TCI API: a stateless web service,/tci/v1, that hands a real target-controlled infusion pump its next rate from the pump's own record of what it has delivered (run_tci_api(), ortciNextRate()from R). FauxTCI is a simulated pump in the browser built to it, showing every request and response as it runs (source).- The in-app help — the Help tab in the running app: a user's guide, a generated page
for every drug (parameters at reference patients, citation, units), the models and methods,
loadable teaching scenarios, the investigators, and a map of this repository. The hand-written
pages are Markdown in
inst/app-help/(seeinst/app-help/README.md); the drug and scenario pages are generated from the code byR/help-drugs.RandR/help-scenarios.R.
- Check the required R version by looking at the
RVersionfield near the top of the filerenv.lock - Download and install the required R version
- Clone/download this repository to your local machine
- Open the
stanpumpR.Rprojfile in RStudio - Run
renv::restore()to install all the necessary packages - Make a copy of the file
config.yml.sampleas a new file namedconfig.yml. Thisconfig.ymlis a configuration file that stanpumpR needs. You can change the settings inside it. - Run the app from the RStudio Console:
devtools::load_all(".") run_app() - Debug mode shows a detailed log and a performance profiler. By default, debug mode is off in production. You can turn it on by adding
?debug=1to the URL (&debug=1if it already has a query).
- Install the devtools package via
install.packages("devtools"). - Install all package dependencies via
devtools::install_deps(dependencies = TRUE) - Run the tests via
devtools::test()
A limited number of functions have been exported for use by your own code.
On Windows, install the ready-made package. It is rebuilt from master on every change and
published as the windows-binary release:
one zip for x64 and ARM, built with the current R release (install it in the same R minor version).
zip <- file.path(tempdir(), "stanpumpR.zip")
download.file("https://github.com/StevenLShafer/stanpumpR/releases/download/windows-binary/stanpumpR.zip",
zip, mode = "wb")
install.packages(zip, repos = NULL, type = "win.binary")
library(stanpumpR)Install the CRAN packages in Imports first if you don't have them; the release notes list them.
Installing from source on Windows (remotes::install_github(), pak, devtools::install()) can
fail with nothing but ERROR: lazy loading failed for package 'stanpumpR'. On Windows 11 the
cause has been Smart App Control, which blocked a DLL during the build because it could not
verify where the DLL came from. The zip is already built, so installing it skips that step. It is built by
.github/workflows/windows-binary.yaml, which also installs it into an empty library and runs a
simulation before publishing it.
On macOS or Linux, install from GitHub:
# install.packages("remotes")
remotes::install_github("StevenLShafer/stanpumpR")or, from a clone of the repository, devtools::install(build_vignettes = TRUE).
To simulate a dose table from a script, call apiSimulate(), or start the HTTP service with
run_api() (needs the plumber package). Both are described at
stanpumpr.io/api.
When code is merged into the default branch, it is deployed to production automatically once the R-CMD-check workflow has passed on it. Pull Requests carrying the DEPLOY label are deployed to a test environment for testing; the label is added automatically to a pull request from this repository, and by a maintainer to one from a fork.
This project uses {renv} to lock R package versions. This is mainly done so that we can take control of package versions for the production shiny app, which is a major step towards a stable app. The renv.lock file is committed to the repo and is used to ensure the deployed app uses the exact same package versions as those tested locally.
Adding a new package — add it to DESCRIPTION first, then install and snapshot:
renv::install("pkgname") # install into the renv library
renv::snapshot() # update renv.lock
# commit both DESCRIPTION and renv.lockUpdating an existing package:
renv::update("pkgname")
renv::snapshot()
# commit renv.lockAfter pulling changes that include renv.lock updates:
renv::restore()Steven L. Shafer, MD November 2026