# Repeat a pure function call
frepeat(times = 3, expr = function() rnorm(1))
# Repeat a function with input `.x`
frepeat(.x = 10, times = 3, expr = function(x) rnorm(1, mean = x))
# Repeat an unevaluated expression (evaluated with `eval()`)
frepeat(times = 2, expr = quote(rnorm(1)))
# Simplify the output to an array
frepeat(times = 3, expr = function() rnorm(1), simplify = TRUE)
# Monte Carlo simulation: estimate coverage of a 95% CI for sample mean
mc_result <- frepeat(times = 1000, simplify = TRUE, pb = TRUE, ncores = 1, expr = function() {
sample <- rnorm(30, mean = 0, sd = 1)
ci <- t.test(sample)$conf.int
mean(ci[1] <= 0 & 0 <= ci[2]) # check if true mean is inside the interval
})
mean(mc_result) # estimated coverage
Run the code above in your browser using DataLab