run <- FALSE
root_dir <- paste(rep("../", 1), collapse = "")
knitr::opts_chunk$set(comment = "#>", collapse = TRUE)
knitr::opts_knit$set(root.dir = root_dir)

TODO

Create instance

createInstance(of = "test_class")
createInstance(of = "test_class", with = letters[1:3])
createInstance(of = "test_class", with = letters[1:3])
createInstance(of = "test_class", with = letters[1:3],
  attributes = list(attr_1 = TRUE, attr_2 = "yep!"))
createInstance(of = "test_class", with = letters[1:3],
  attributes = list(my_attrs = list(attr_1 = TRUE, attr_2 = "yep!")))

Use in S3 methods

Create methods

foo <- function(x, ...) {
  UseMethod("foo", x)
}

foo.test_class <- function(x, context = NULL) {
  UseMethod("foo.test_class", context)
}

foo.test_class1.NULL <- function(x, context = NULL) {
  "Hello World!"
}

foo.test_class1.Context1 <- function(x, context) {
  "I'm the method for context 1"
}

foo.test_class1.Context2 <- function(x, context) {
  "I'm the method for context 2"
}

Call methods

x <- createInstance("test_class1")
foo(x)

ctxt_1 <- createInstance("Context1")
foo(x = x, context = ctxt_1)

ctxt_2 <- createInstance("Context2")
foo(x = x, context = ctxt_2)


rappster/instancer documentation built on May 26, 2019, 11:17 p.m.