Learn R Programming

campsis

Requirements

  • R package campsismod must be installed beforehand
  • Simulation engine must be installed too (rxode2 or mrgsolve)

Installation

Install the latest stable release using devtools:

devtools::install_github("Calvagone/campsis")

Basic example

Import the campsis package:

library(campsis)

Create your dataset:

ds <- Dataset(50) %>%
  add(Bolus(time = 0, amount = 1000, ii = 12, addl = 2)) %>%
  add(Observations(times = seq(0, 36, by = 0.5)))

Load your own model or use a built-in model from the library:

model <- model_suite$pk$`2cpt_fo`

Simulate your results with your preferred simulation engine (rxode2 or mrgsolve):

results <- simulate(model = model, dataset = ds, dest = "mrgsolve", seed = 1)

Plot your results:

shaded_plot(results, "CONC")

Copy Link

Version

Install

install.packages('campsis')

Monthly Downloads

697

Version

1.9.2

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Nicolas Luyckx

Last Published

September 24th, 2026

Functions in campsis (1.9.2)

IOV

Define inter-occasion variability (IOV) into the dataset. A new variable of name 'colname' will be output into the dataset and will vary at each dose number according to the given distribution.
Infusion

Create one or several infusion(s).
DiscreteDistribution

Discrete distribution.
Outfun

Create a new output function
Hardware

Create hardware settings.
Observations

Create an observations list. Please note that the provided 'times' will automatically be sorted. Duplicated times will be removed.
DoseAdaptation

Create a dose adaptation.
LogNormalDistribution

Create a log normal distribution.
NCATableOutfun

Create a NCA table output function
PI

Compute the prediction interval summary over time (deprecated).
Outfuns

Create a collection of output functions.
FunctionDistribution

Create a function distribution. During distribution sampling, the provided function will be responsible for generating values for each sample. If first argument of this function is not the size (n), please tell which argument corresponds to the size 'n' (e.g. list(size="n")).
FixedDistribution

Create a fixed distribution. Each sample will be assigned a fixed value coming from vector 'values'.
SimulationProgress

Create a simulation progress object.
Events

Create a list of interruption events.
RepeatAtSchedule

'Repeat at' schedule constructor. Note that the time 0 for the base pattern will be added by default if not provided.
TimeVaryingCovariate

Create a time-varying covariate. This covariate will be implemented using EVID=2 rows in the exported dataset and will not use interruption events.
NOCB

Create NOCB settings.
NormalDistribution

Create a normal distribution.
Settings

Create advanced simulation settings.
Scenario

Create an scenario.
PIOutfun

Create a prediction interval output function
TimeSequence

Instantiate a new time sequence.
Occasion

Define a new occasion. Occasions are defined by mapping occasion values to dose numbers. A new column will automatically be created in the exported dataset.
apply_outfun

Apply output function(s) on the given Campsis results.
Scenarios

Create a list of scenarios.
apply_scenario

Apply scenario to the given model or dataset.
ReplaceAction

Create a replace action.
DefaultOutfun

Default output function (identity function).
as.numeric,time_vector-method

Time vector to numeric vector.
as.numeric,time_sequence-method

Time sequence to numeric vector.
bolus_wrapper-class

Bolus wrapper class.
bootstrap-class

Bootstrap class.
bootstrap_distribution-class

Bootstrap distribution class.
bolus-class

Bolus class.
apply_action

Apply some action on the given object.
UniformDistribution

Create an uniform distribution.
TimeVector

Instantiate a new time vector
convert_time

Convert numeric time vector based on the provided units.
convertTime

Convert numeric time vector based on the provided units.
apply_compartment_characteristics

Apply compartment characteristics from model. In practice, only compartment infusion duration needs to be applied.
Progress

Create progress settings.
DefaultSettings

Create default settings.
campsis_handler

Suggested Campsis handler for showing the progress bar.
arm-class

Arm class.
cyclic_schedule-class

Cyclic schedule class.
campsis_metadata-class

Campsis metadata class.
cutTableForEvent

Cut table according to given iteration.
days

Convert days to hours.
arms-class

Arms class.
ParameterDistribution

Create a parameter distribution. The resulting distribution is a log-normal distribution, with meanlog=log(THETA) and sdlog=sqrt(OMEGA).
Solver

Create solver settings.
EventIteration

Create an event iteration object.
EventRelatedObservations

Create an event-related observations list. Please note that the provided 'times' will automatically be sorted. Duplicated times will be removed.
StatsOutfun

Create a statistics output function
declare_settings-class

Declare settings class.
dosing_schedule-class

Dosing schedule class.
dosing_only

Filter Campsis output on dosing rows.
default_outfun-class

Default output function class.
covariates-class

Covariates class.
default_settings-class

Default settings class.
dose_adaptations-class

Dose adaptations class.
covariate-class

Covariate class.
fillIOVOccColumns

Fill IOV/Occasion columns.
check_ii_and_addl

Check ii and addl arguments in addition to time.
fixed_covariate-class

Fixed covariate class.
dose_adaptation-class

Dose adaptation class.
assign_dose_number

Assign dose number to each treatment entry.
generate_iiv_

Generate IIV matrix for the given OMEGA matrix.
binomial_distribution-class

Binomial distribution class.
export_delegate

Export delegate method. This method is common to RxODE and mrgsolve.
export_table_delegate

Export table delegate.
compute_stats

Compute generic statistics over time.
distribution-class

Distribution class. See this class as an interface.
get_available_time_units

Return the list of available time units.
discrete_distribution-class

Discrete distribution class.
compute_pi

Compute the prediction interval summary over time.
dataset_config-class

Dataset configuration class.
function_distribution-class

Function distribution class.
constant_distribution-class

Constant distribution class.
campsis_tbl-class

Campsis table class (see this class as an interface)
generate_iiv

Generate IIV matrix for the given Campsis model.
compute_incremental_progress

Compute incremental progress.
getTimeVaryingVariables

Get all time-varying variables. These variables are likely to be influenced by the NOCB mode chosen and by the 'nocbvars' vector.
counterBalanceLocfMode

Counter-balance LOCF mode for occasions & IOV. This function will simply shift all the related occasion & IOV columns to the left (by one).
.assert_variable_present

Assert that one or more variable columns are present in the data.
.auto_strata

Detect VPC stratification variable automatically.
counterBalanceNocbMode

Counter-balance NOCB mode for occasions & IOV. This function will simply shift all the related occasion & IOV columns to the right (by one).
.is_replicated

Does the data contain more than one replicate?
get_fixed_covariates

Get all fixed covariates.
get_iovs

Get all IOV objects.
get_initial_conditions

Get initial conditions at simulation start-up.
get_times

Get all distinct times for the specified object.
hardware_settings-class

Hardware settings class.
event-class

Event class.
get_compartment_mapping

Get a mapping table with all possibilities of compartment names and their indexes knowing that compartment names can be provided as character or as integer.
get_campsis_options

Get the Campsis options (R options).
get_column

Get data of given column unless if does not exist (return NULL in that case).
get_random_seed_value

Get random seed value.
length,arm-method

Return the number of subjects contained in this arm.
fixed_distribution-class

Fixed distribution class.
get_campsis_option

Get Campsis option logic.
lognormal_distribution-class

Log normal distribution class.
length,dataset-method

Return the number of subjects contained in this dataset.
get_covariates

Get all covariates (fixed / time-varying / event covariates).
get_event_covariates

Get all event-related covariates.
drop_others

Return the 'DROP_OTHERS' string that may be used in the 'outvars' vector for RxODE/mrgsolve to drop all others variables that are usually output in the resulting data frame.
make_vpc_summary

Make the VPC summary. Input data frame must contain the following columns: - replicate: replicate number - low: low percentile value in replicate (and in scenario if present) - med: median value in replicate (and in scenario if present) - up: up percentile value in replicate (and in scenario if present) - any scenario column
get_simulation_engine_type

Get simulation engine type.
dataset-class

Dataset class.
mergeTimeVaryingCovariates

Merge time-varying covariates into a single data frame. This last data frame will be merged afterwards with all treatment and observation rows.
length,repeat_at_schedule-method

Return the number of repetition cycles.
observations-class

Observations class.
obs_only

Filter Campsis output on observation rows.
internal_settings-class

Internal settings class (transient object from the simulation settings).
on_cran

Check if the current session is on CRAN. The objective is to potentially suppress long tasks to be run on CRAN (long tests or vignettes).
get_seed

Get seed value.
open_json

Open JSON file.
minutes

Convert minutes to hours.
getEventIterations

Get list of event iterations.
events-class

Events class.
iov-class

Treatment IOV class.
pi_outfun-class

Prediction interval output function class.
nocb_settings-class

NOCB settings class.
normal_distribution-class

Normal distribution class.
infusion-class

Infusion class.
event_covariate-class

Event covariate class.
hours

Convert hours to hours (do nothing).
pi_campsis_tbl-class

Prediction Interval (PI) Campsis table class
reorder_columns

Reorder output columns.
get_seed_for_iteration

Get seed for iteration.
preprocess_slices

Preprocess 'slices' argument.
remove_initial_conditions

Remove initial conditions.
preprocess_tablefun

Pre-process tablefun argument.
get_seed_for_dataset_export

Get seed for dataset export.
retrieve_parameter_value

Retrieve the parameter value (standardized) for the specified parameter name.
getDatasetMaxTime

Get dataset max time.
preprocess_scenarios

Pre-process scenarios. Please note that only the enabled scenarios will be retained for the simulation.
preprocess_settings

Preprocess the simulation settings.
preprocessNocbvars

Preprocess 'nocbvars' argument.
preprocessTSLDAndTDOSColumn

Preprocess TSLD and TDOS columns according to given dataset configuration.
left_join_iiv

Left-join IIV matrix.
.auto_colour_columns

Detect colour stratification columns automatically.
get_seed_for_parameters_sampling

Get seed for parameter uncertainty sampling.
rxode_engine-class

rxode2 engine class.
sample_distribution_as_tibble

Sample a distribution and return a tibble.
import_campsismod_to_namespace

Import the whole campsismod package into NAMESPACE when parsed by 'roxygen'.
preprocess_replicates

Preprocess 'replicates' argument.
infusion_wrapper-class

Infusion wrapper class.
json_to_campsis_settings

JSON to Campsis dataset.
on_ci

Check if the current session is on CI (e.g. GitHub actions).
setupPlanSequential

Setup plan as sequential (i.e. no parallelisation).
sample_covariates_list

Sample covariates list.
occasions-class

Occasions class.
scatterPlot

Scatter plot (or X vs Y plot).
preprocess_dosing

Preprocess 'dosing' argument.
length,cyclic_schedule-method

Return the number of repetition cycles.
setup_plan_default

Setup default plan for the given simulation or hardware settings. This plan will prioritise the distribution of workers in the following order: 1) Replicates (if 'replicate_parallel' is enabled) 2) Scenarios (if 'scenario_parallel' is enabled) 3) Dataset export / slices (if 'dataset_export' or 'slice_parallel' is enabled)
simulate_scenarios

Simulation scenarios.
preprocess_ids

Preprocess subjects ID's.
nhanes

NHANES database (demographics and body measure data combined, from 2017-2018).
simulate_delegate_core

Simulation delegate core (single replicate).
scenarios-class

Scenarios class.
nca_table_outfun-class

NCA table output function class.
scenario_action-class

Scenario action class.
repeat_schedule

Repeat schedule.
mrgsolve_engine-class

mrgsolve engine class.
repeat_at_schedule-class

'Repeat at' schedule class.
get_occasions

Get all occasions.
get_splitting_configuration

Get splitting configuration for parallel export.
preserve_column_levels

Preserve Existing Column Value Order as Factor Levels
set_subjects

Set the number of subjects.
sample

Sample generic object.
preprocess_events

Pre-process events.
months

Convert pharma months (1 month = 4 weeks) to hours.
simulation_settings-class

Simulation settings class.
solver_settings-class

Solver settings class. See ?mrgsolve::update. See ?rxode2::rxSolve.
get_time_varying_covariates

Get all time-varying covariates.
outfun-class

Output function class.
scatter_plot.std_campsis_tbl

Scatter plot for standard Campsis simulation output.
outfuns-class

Output functions class (i.e. a collection of output functions).
is_empty_bootstrap

Is the given bootstrap empty.
preprocess_outvars

Preprocess 'outvars' argument. 'Outvars' is a character vector which tells Campsis the mandatory columns to keep in the output dataframe.
setupPlanDefault

Setup default plan for the given simulation or hardware settings. This plan will prioritise the distribution of workers in the following order: 1) Replicates (if 'replicate_parallel' is enabled) 2) Scenarios (if 'scenario_parallel' is enabled) 3) Dataset export / slices (if 'dataset_export' or 'slice_parallel' is enabled)
processAllTimeColumns

Process time-related columns according to given dataset configuration.
time_sequence-class

Time sequence class.
spaghetti_plot.std_campsis_tbl

Spaghetti plot for standard Campsis simulation output.
sampleTimeVaryingCovariates

Sample time-varying covariates.
setLabel

Set the label.
preprocess_outfun

Pre-process outfun argument.
process_arm_labels

Process arm labels. Arm identifiers in ARM column are replaced by arm labels as soon as one arm label is provided.
time_varying_covariate-class

Time-varying covariate class.
process_simulate_arguments

Preprocess arguments of the simulate method.
splitDataset

Split dataset according to config.
simulate

Simulate function.
scenario-class

Scenario class.
process_drop_others

Process 'DROP_OTHERS'.
json_to_campsis_dataset

JSON to Campsis dataset.
preprocess_arm_column

Preprocess ARM column. Add ARM equation in model automatically.
observations_set-class

Observations set class.
simulation_engine-class

Simulation engine class.
replace_action-class

Replace action class.
treatment_iovs-class

Treatment IOV's class.
repeated_schedule-class

Repeated schedule class. See this class as an interface.
scatter_plot

Scatter plot (S3 generic).
setSubjects

Set the number of subjects.
simulate_delegate

Simulation delegate (several replicates).
scenario_actions-class

Scenario actions class.
setup_plan_sequential

Setup plan as sequential (i.e. no parallelisation).
vpcPlot

VPC plot.
unite_columns

Unite the given column names.
vec_restore.campsis_tbl

Restore a campsis_tbl object
uniform_distribution-class

Uniform distribution class.
set_seed

Set the seed. The goal of this method is to centralize all calls to the R method 'set.seed'.
set_label

Set the label.
time_vector-class

Time vector class.
standardise_time

Standardise time to hours.
shaded_plot

Shaded plot / prediction interval plot (S3 generic).
occasion-class

Occasion class.
shaded_plot.std_campsis_tbl

Shaded plot for standard Campsis simulation output.
vpc_plot.std_campsis_tbl

VPC plot for standard Campsis simulation output.
stats_campsis_tbl-class

Statistics Campsis table class
simulation_progress-class

Simulation progress class.
unwrap_treatment

Unwrap treatment.
preprocess_dest

Pre-process destination engine. Throw an error message if the destination engine is not installed.
weeks

Convert weeks to hours.
years

Convert pharma years (1 year = 12*4 weeks) to hours.
undefined_schedule-class

Undefined schedule class.
stats_outfun-class

Statistics output function class.
undefined_distribution-class

Undefined distribution class. This type of object is automatically created in method to_explicit_distribution() when the user does not provide a concrete distribution. This is because S4 objects do not accept NULL values.
shadedPlot

Shaded plot (or prediction interval plot).
seconds

Convert seconds to hours.
std_campsis_tbl-class

Standard Campsis table class
update_ii

Update the inter-dose interval (II).
protocol-class

Protocol class.
vpc_plot.pi_campsis_tbl

VPC plot for prediction-interval Campsis output.
update_repeat

Update the repeat field (argument 'rep' in Bolus and Infusion constructors).
progress_settings-class

Progress settings class.
update_addl

Update the number of additional doses (ADDL).
remove_column_levels

Strip Factor Class from Columns
to_explicit_distribution

Convert user-given distribution to an explicit Campsis distribution. Passed distribution can be: - a NULL value. In that case, it will be converted into an 'UndefinedDistribution'. - a single numeric value. In that case, it will be converted into a 'ConstantDistribution'. - a numeric vector. In that case, it will be converted into a 'FixedDistribution'. - all available types of distribution. In this case, no conversion is applied.
spaghetti_plot

Spaghetti plot (S3 generic).
vpc_plot

VPC plot (S3 generic).
update_amount

Update amount.
toDatasetSummary

Convert dataset to dataset summary (internal method).
spaghettiPlot

Spaghetti plot.
treatment-class

Treatment class.
Covariate

Create a non time-varying (fixed) covariate.
Arm

Create a treatment arm.
Dataset

Create a dataset.
CyclicSchedule

Cyclic schedule constructor.
BootstrapDistribution

Create a bootstrap distribution. During function sampling, Campsis will generate values depending on the given data and arguments.
ConstantDistribution

Create a constant distribution. Its value will be constant across all generated samples.
Bootstrap

Create a bootstrap object.
Declare

Create declare settings.
DatasetSummary

Create a dataset summary (internal method).
BinomialDistribution

Binomial distribution.
EventCovariate

Create an event covariate. These covariates can be modified further in interruption events.
Event

Create an interruption event.
DatasetConfig

Create a dataset configuration. This configuration allows Campsis to know which are the default depot and observed compartments.
Bolus

Create one or several bolus(es).
EtaDistribution

Create an ETA distribution. The resulting distribution is a normal distribution, with mean=0 and sd=sqrt(OMEGA).
DosingSchedule

Dosing schedule constructor.