Learn R Programming

⚠️There's a newer version (1.2.1) of this package.Take me there.

campsismod

Installation

Install the latest stable release using devtools:

devtools::install_github("Calvagone/campsismod")

Basic examples

Load example from model library

Load 2-compartment PK model from built-in model library:

library(campsismod)
model <- model_suite$pk$`2cpt_fo`

Write CAMPSIS model

model %>% write(file="path_to_model_folder")
list.files("path_to_model_folder")
#> [1] "model.campsis" "omega.csv"     "sigma.csv"     "theta.csv"

Read and show CAMPSIS model

model <- read.campsis(file="path_to_model_folder")
show(model)
#> [MAIN]
#> TVBIO=THETA_BIO
#> TVKA=THETA_KA
#> TVVC=THETA_VC
#> TVVP=THETA_VP
#> TVQ=THETA_Q
#> TVCL=THETA_CL
#> 
#> BIO=TVBIO
#> KA=TVKA * exp(ETA_KA)
#> VC=TVVC * exp(ETA_VC)
#> VP=TVVP * exp(ETA_VP)
#> Q=TVQ * exp(ETA_Q)
#> CL=TVCL * exp(ETA_CL)
#> 
#> [ODE]
#> d/dt(A_ABS)=-KA*A_ABS
#> d/dt(A_CENTRAL)=KA*A_ABS + Q/VP*A_PERIPHERAL - Q/VC*A_CENTRAL - CL/VC*A_CENTRAL
#> d/dt(A_PERIPHERAL)=Q/VC*A_CENTRAL - Q/VP*A_PERIPHERAL
#> 
#> [F]
#> A_ABS=BIO
#> 
#> [ERROR]
#> CONC=A_CENTRAL/VC
#> if (CONC <= 0.001) CONC=0.001
#> CONC_ERR=CONC*(1 + EPS_PROP_RUV)
#> 
#> 
#> THETA's:
#>   name index value   fix                            label unit
#> 1  BIO     1     1 FALSE                  Bioavailability <NA>
#> 2   KA     2     1 FALSE                  Absorption rate  1/h
#> 3   VC     3    10 FALSE    Volume of central compartment    L
#> 4   VP     4    40 FALSE Volume of peripheral compartment    L
#> 5    Q     5    20 FALSE           Inter-compartment flow  L/h
#> 6   CL     6     3 FALSE                        Clearance  L/h
#> OMEGA's:
#>   name index index2 value   fix type
#> 1   KA     1      1    25 FALSE  cv%
#> 2   VC     2      2    25 FALSE  cv%
#> 3   VP     3      3    25 FALSE  cv%
#> 4    Q     4      4    25 FALSE  cv%
#> 5   CL     5      5    25 FALSE  cv%
#> SIGMA's:
#>       name index index2 value   fix type
#> 1 PROP_RUV     1      1   0.1 FALSE   sd
#> No variance-covariance matrix
#> 
#> Compartments:
#> A_ABS (CMT=1)
#> A_CENTRAL (CMT=2)
#> A_PERIPHERAL (CMT=3)

Simulate with rxode2 or mrgsolve

library(campsis)

dataset <- Dataset(5) %>%
  add(Bolus(time=0, amount=1000, ii=12, addl=2)) %>%
  add(Observations(times=0:36))

rxode <- model %>% simulate(dataset=dataset, dest="rxode2", seed=0)
mrgsolve <- model %>% simulate(dataset=dataset, dest="mrgsolve", seed=0)
spaghettiPlot(rxode, "CONC")
spaghettiPlot(mrgsolve, "CONC")

Copy Link

Version

Install

install.packages('campsismod')

Monthly Downloads

705

Version

1.1.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Nicolas Luyckx

Last Published

February 16th, 2024

Functions in campsismod (1.1.1)

Compartment

Create a compartment.
InfusionDuration

Create an infusion duration.
IfStatement

Create a new IF-statement.
MainRecord

Create MAIN code record.
Ode

Create a new ordinary differential equation (ODE).
ModelStatements

Create an empty list of model statements.
UnknownStatement

Create a new ordinary differential equation (ODE).
appendCodeRecords

Append code records
OdeRecord

Create ODE code record.
InfusionRate

Create an infusion rate.
Sigma

Create a SIGMA parameter.
InitialCondition

Create an initial condition.
UnsupportedDestException

Unknown destination engine exception.
appendComment

Append comment.
addODECompartment

Add ODE compartment to compartments object.
autoDetectNONMEM

Auto-detect special variables from NONMEM as compartment properties. Bioavailabilities, infusion durations/rates and lag times will be automatically detected.
assertSingleCharacterString

Assert the given character vector is a single character string.
addProperties

Add properties to compartments object.
compartment_infusion_rate-class

Compartment infusion rate class.
Bioavailability

Create a bioavailability for the specified compartment.
compartment_initial_condition-class

Compartment initial condition class.
duration_record-class

(Infusion)-duration record class.
double_array_parameter-class

Double-array parameter class. This parameter has 2 indexes. It can thus be used to define correlations between parameters.
Pattern

Create a pattern.
CampsisModel

Create a new CAMPSIS model.
export_type-class

Export type class.
export

Export function.
appendModel

Append model (or simply add).
Theta

Create a THETA parameter.
appendCompartments

Append compartments.
getUncertainty

Get uncertainty on the parameters.
compartment_property-class

Compartment property class.
CodeRecords

Create a list of code records.
Comment

Create a new comment.
LagTime

Create a lag time for the specified compartment.
LineBreak

Create a new line break.
VariablePattern

Create a variable pattern.
add

Add element to list.
isEquation

Say if line in record is an equation not.
isEmptyLine

Check if string is an empty line.
compartments-class

Compartments class.
getVarCov

Get variance-covariance matrix.
as.data.frame

As data frame method.
appendParameters

Append parameters.
campsis_model-class

CAMPSIS model class.
code_record-class

Code record class. See this code record as an abstract class. 2 implementations are possible: - properties record (lag, duration, rate & bioavailability properties) - statements record (main, ode & error records)
Position

Element position in list.
Omega

Create an OMEGA parameter.
Parameters

Create a list of parameters.
convertOutvarsToCapture

Convert outvars argument to capture. Variables that are already in error block will be discarded.
maxIndex

Max index.
addSuffix

Generic function to add a suffix to various objects like parameters, code records, compartment names or a model (all previous objects at the same time). This makes it an extremely powerful function to combine 2 models or more (using function 'add'), that have similar equation, parameter or compartment names.
methodsGlobalFunctions

A empty method only used to declare some of the global function definitions contained in the package 'methods', which are used intensively.
mrgsolve_type-class

Mrgsolve export type class.
allNa

Check is vector has NA's only.
compartment_lag_time-class

Compartment lag time class.
processDoubleArrayArguments

Process double array arguments.
ode-class

ODE class. Any statement in the form d/dt(A_CMT) = B.
processExtraArg

Process extra arguments.
replace

Replace element by another in list.
default

Get default element from list.
removeTrailingLineBreaks

Remove all trailing line breaks.
compartment-class

Compartment class.
compartment_properties-class

Compartment properties class.
comment-class

Comment class. A statement starting with #.
contains

Check if an element exists in list.
equation-class

Equation class. Any statement in the form A = B.
error_record-class

Error record class.
convertAnyComment

Convert CAMPSIS comment style to C/C++ code. Only the first # is translated to //.
compartment_bioavailability-class

Compartment bioavailability class.
compartment_infusion_duration-class

Compartment infusion duration class.
delete

Delete an element from this list.
fixOmega

Fix omega matrix for SAME OMEGA parameters that have NA values due to imperfections in Pharmpy import.
find

Find an element in list.
disable

Disable.
f_record-class

Bioavailability record class.
extractTextBetweenBrackets

Extract text between brackets.
getCompartmentIndex

Get the compartment index for the specified compartment name.
getCompartments

Detect all compartments names from the code records. Only for model instantiation. Not exported.
getByIndex

Get element by index.
ifStatementPatternStr

Return the IF-statement pattern (string form).
getByName

Get an element from a list by name. Never return more than 1 element.
getNameInModel

Get the name of the given parameter in the CAMPSIS model.
extractLhs

Extract left-hand-side expression.
getNONMEMName

Get NONMEM name.
extractRhs

Extract right-hand-side expression.
getNames

Get element names from list.
if_statement-class

If-statement class. Any statement in the form if (condition) A = B.
getName

Get element name.
getPrefix

Get prefix.
indexOf

Get the index of an element in list.
init_record-class

Init record class.
getRecordDelimiter

Get record delimiter.
isStrictRecordDelimiter

Is strict record delimiter. A strict record delimiter is any line starting with [...] and followed by nothing but spaces or a possible comment.
model_statement-class

Model statement class. Any statement in a code record.
minIndex

Min index.
isRecordDelimiter

Is record delimiter. A record delimiter is any line starting with [...].
getRecordName

Get record name.
isIfStatement

Say if line in record is an IF-statement.
isODE

Say if line(s) in record is/are ODE or not.
getRecordEquationNames

Get record equation names
matchSingleArrayParameter

Match single array parameter from list based on the name instead of the index. If a match is found, its index is automatically copied.
matchDoubleArrayParameter

Match double array parameter from list based on the name instead of the index. If a match is found, its indexes are automatically copied.
pmx_list-class

PMX list class.
lag_record-class

Lag record class.
pmx_position-class

PMX position class.
length,pmx_list-method

Return the length of this list.
model_statements-class

Model statements class. A list of statements.
model_suite

CAMPSIS model suite.
parameter-class

Parameter class. Any parameter in a pharmacometric model.
mrgsolveMain

Get the MAIN block for mrgsolve.
mrgsolveCompartment

Get the compartment block for mrgsolve.
hasComment

Check if string contains CAMPSIS-style comments.
pmx_position_by_element-class

PMX position by element class.
mrgsolveParam

Get the parameters block for mrgsolve.
%>%

Magritt operator for piping.
isComment

Check if string is a CAMPSIS comment (i.e. not an equation).
mrgsolveMatrix

Get the OMEGA/SIGMA matrix for mrgsolve.
omega-class

Omega parameter class.
mrgsolveOde

Get the ODE block for mrgsolve.
ode_record-class

ODE record class.
parameters-class

Parameters class.
pmx_position_by_index-class

PMX position by index class.
toString

ToString generic method.
rxodeCode

Get code for RxODE.
replaceAll

Replace all occurrences in object.
read.campsis

Read a CAMPSIS model.
trim

Trim character vector. Remove all leading and trailing spaces.
writeVarcov

Write variance-covariance matrix.
read

Generic read method to read data from a file or a folder.
rxodeParams

Get the parameters vector for RxODE.
read.model

Read model file.
rxodeMatrix

Get the OMEGA/SIGMA matrix for RxODE.
read.allparameters

Read all parameters files at once.
isDiag

Is diagonal.
mrgsolveTable

Get the TABLE block for mrgsolve.
line_break-class

Line-break class. A linebreak in the model.
pattern-class

Pattern class.
pmx_element-class

PMX element class.
main_record-class

Main record class.
sort

Sort the specified list.
mrgsolveBlock

Convert code record for mrgsolve.
standardise

Standardise.
sigma-class

Sigma parameter class.
single_array_parameter-class

Single-array parameter class. This parameter has a single index value.
variable_pattern-class

Variable pattern class.
write

Write generic object to files.
parseIfStatement

Parse IF-statement. Assumption: isIfStatement method already called and returned TRUE.
mrgsolveCapture

Get the CAPTURE block for mrgsolve.
parseStatements

Parse statements code and return CAMPSIS statements.
properties_record-class

Properties record class.
rate_record-class

(Infusion)-rate record class.
variablePatternNoStartStr

Return the variable pattern (string form), without the first character.
writeRecordDelimiter

Write record delimiter line.
select

Get a subset of an object.
read.parameters

Read parameters file.
variablePatternStr

Return the variable pattern (string form).
writeParameters

Write subset of parameters (theta, omega or sigma).
rxode_type-class

RxODE export type class.
read.varcov

Read variance-covariance file.
read.pmxmod

Read a CAMPSIS model (deprecated).
removeNaColumn

Remove given column(s) if it has only NA's.
statements_record-class

Statements record class.
unknown_statement-class

Unknown statement class. Any statement not recognized by campsismod.
theta-class

Theta parameter class.
updateCompartments

Update compartments list from the persisted records. Exported especially for package pmxtran. However, this method should not be called.
Compartments

Create a list of compartments
Equation

Create a new equation.
ErrorRecord

Create ERROR code record.