I am fitting a model 9000 times to random samples from my data using for loops. One run of the code fills about 70GB of hard drive space. Any idea what’s going on?

The model is compiled outside the loop and then fit using the sampling function. No objects exist in the R environment after the run that would add up to 70GB. The code is run through the following R chuck in an Rmd file.

`rstan_options(auto_write = TRUE) options(mc.cores = parallel::detectCores()) hurdle_sim <- tibble(iter = numeric(), coverage = numeric(), MO_true = numeric(), MO_pred = numeric() ) # Compile Stan model to avoid recompiling in the loop. hurdle_model <- stan_model(file = "interaction_hurdle_model.stan") for (i in 1:1000) { for (j in seq(10, 90, by = 10)) { sim_dat <- sample_n(ffmm.dat.p2001, 134) sim_obs <- sample_n(sim_dat, round(134 * (j / 100))) stan_dat <- list(N = length(sim_obs$MO_TotCat), y = sim_obs$MO_TotCat, unobs = 134 - length(sim_obs$MO_TotCat), shape = MO_shape_hand, rate = MO_rate_hand) fit <- sampling(object = hurdle_model, data = stan_dat, iter = 1000, chains = 4, open_progress = F, verbose = F) pred <- as.data.frame(extract(fit, pars = "y_pred")) %>% summarize_all(mean) %>% mutate(sum_unobs = rowSums(.)) MO_pred <- sum(sim_obs$MO_TotCat) + pred$sum_unobs hurdle_sim <- hurdle_sim %>% add_row(iter = i, coverage = j, MO_true = sum(sim_dat$MO_TotCat, na.rm = T), MO_pred = MO_pred) } }`

Operating System: Windows 10

R version: 3.5.1

RStan release: 2.17.2