test_that("construct() and deconstruct() work for S3 (functions)", {
car <- function(.x = list(), name, mpg, cyl, .class = character()) {
.x$name <- name
.x$mpg <- mpg
.x$cyl <- cyl
structure(
.x,
class = c(.class, "car")
)
}
test_construct(test_cars, "car")
test_construct(test_cars, car, "car")
rm(car)
})
test_that("construct() and deconstruct() work for S4", {
setClass(
"Car",
slots = c(
name = "character",
mpg = "numeric",
cyl = "numeric"
)
)
test_construct(test_cars, "Car")
test_construct(test_cars, getClass("Car"), "Car")
methods::removeClass("Car")
})
test_that("construct() and deconstruct() work for R6", {
Car <- R6Class(
classname = "Car",
public = list(
initialize = function(name, mpg, cyl) {
self$name <- name
self$mpg <- mpg
self$cyl <- cyl
},
name = NULL,
mpg = NULL,
cyl = NULL
)
)
test_construct(test_cars, "Car")
test_construct(test_cars, Car, Car$classname)
rm(Car)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.