# devtools::install_github(repo = "MikeKSmith/rspeaksnonmem")
# devtools::install_github(repo = "MangoTheCat/RNMImport")

library(rspeaksnonmem)
setwd(".")
file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"),
                           "warfarin_conc_pca.csv"),
            to = getwd(), overwrite = T )
file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"),
                           "warfarin.ctl"),
            to = getwd(), overwrite = T )
file.rename(from = "warfarin.ctl", "run0.ctl")

Being able to run PsN from within R means that you can easily combine execution with the PsN output plot markdown files (.Rmd files within the PsN working directory). Here we're going to run the PsN execute function with the option to create diagnostic plots rplots=1.

We have parameterised this report by including the following parameters in the YAML header for this report:

---
title: "rspeaksnonmem with PsN rplots .Rmd files"
author: "Mike K Smith"
date: "03 July 2017"
output: html_document
params: 
  rplots: 1
  psnRunDir: "run0"
---

We can then use these parameters within the R code by referencing params$rplots or params$psnRunDir. Having these as parameters of the document means that we can re-run the document and change these parameters without having to change code within the document.

Run Execute

execute_PsN(installPath = "c:/strawberry/perl",
            version = "4.7.0",
            modelFile = 'run0.ctl',
            rplots = params$rplots,
            working.dir = params$psnRunDir)

We search within the working directory for the .Rmd file and include this as a child document to this parent markdown file. rplotOutput contains the name of the PsN rplots output .Rmd file. In case we change the option above, we also create a boolean variable includeRplotOutput.

 rplotOutput <- list.files(path = params$psnRunDir,
                           recursive = TRUE,
                           pattern = "plots.Rmd",
                           full.names = TRUE)
 includeRplotOutput <- params$rplots > 0 

We use the boolean includeRplotOutput to conditionally execute the chunk below.




MikeKSmith/rspeaksnonmem documentation built on March 12, 2023, 3:25 p.m.