use_method: Use a method

View source: R/use_method.R

use_methodR Documentation

Use a method


This function calls the specified method, passing along any arguments that have been specified in args. It will typically be used in conjunction with the special object L to dynamically run methods that have been included as simulation levels. This function is a wrapper around and is used in a similar manner. See examples.


use_method(method, args = list())



A character string naming a function that has been declared or loaded via source.


A list of arguments to be passed onto method


The result of the call to method


# The following is a toy example of a simulation, illustrating the use of
# the use_method function.
sim <- new_sim()
create_data <- function(n) { rpois(n, lambda=5) }
est_mean_1 <- function(dat) { mean(dat) }
est_mean_2 <- function(dat) { var(dat) }
sim %<>% set_levels(
  "n" = c(10, 100, 1000),
  "estimator" = c("est_mean_1", "est_mean_2")
sim %<>% set_config(num_sim=1)
sim %<>% set_script(function() {
  dat <- create_data(L$n)
  lambda_hat <- use_method(L$estimator, list(dat))
  return (list("lambda_hat"=lambda_hat))
sim %<>% run()

Avi-Kenny/SimEngine documentation built on Aug. 5, 2023, 12:27 p.m.