"R Session Aborted. R encountered a fatal error..."

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")

I had the same issues in the beginning of my coding career. What kind of OS do you use and on which hardware?

Most likely is that you are running out of RAM. If it runs with smaller data than that's almost certainly the issue.

Yes thats what I wanted to say with my question. For my master thesis i had to buy a new computer, because R-Studio always crashed.

However, there can be other reasons as well, such as mathematical mistakes in your C++ "code" object. As you simulate only 5 * 5 Id´s for me it is pretty much unlikely that it is due to high RAM requirement.

To better help you, it would be great if you could specify at which part you receive the session abortion. Is it already in this line:

mod <- mcode("repa_ddi_mock", code)

or later at this part where you use mrgsim() ?

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")