Hello,
My RStudio is crashing when I run a simulation use mrgsolve. I get a "bomb" icon with "R session Aborted". I am running the following R code below for the simulation. How can I resolve this?
mod <- mcode("repa_ddi", code)
--- 2. Create Population Data (10 Subjects x 50 Simulations = 500 IDs) ---
n_subj <- 5
n_sim <- 5
total_ids <- n_subj * n_sim
idata <- data.frame(ID = 1:(total_ids * 3)) %>%
mutate(
group = case_when(
ID <= total_ids ~ "Repa Alone",
ID <= (total_ids * 2) ~ "400mg Inh (SS)",
TRUE ~ "100mg Inh (SS)"
),
inh_amt = case_when(
group == "400mg Inh (SS)" ~ 400,
group == "100mg Inh (SS)" ~ 100,
TRUE ~ 0
)
)
dosing_data <- idata %>%
group_by(ID) %>%
do({
repa <- ev(amt = 0.5, cmt = 3, time = 144)
if(.$inh_amt > 0) {
inh <- ev(amt = .$inh_amt, cmt = 1, ii = 24, addl = 6, time = 0)
repa <- inh + repa
}
as.data.frame(repa)
}) %>% ungroup()
--- 3. Run Optimized Simulation ---
out <- mod %>%
data_set(dosing_data) %>%
idata_set(idata) %>%
update(start = 144, end = 168, delta = 0.1) %>%
obsonly() %>%
mrgsim() %>%
as.data.frame() %>%
select(ID, time, CP_Repa, INH) %>%
mutate(time_norm = time - 144) %>%
left_join(idata, by = "ID")