Nothing
# the constructions doesn't change across R versions, but the indention does
# due to srcref things and the way testthat reads and outputs code
test_that("R6Class, R >= 4.3.0", {
skip_if(with_versions(R < "4.3.0"))
expect_snapshot({
# example from `?R6::R6Class`
Queue <- R6::R6Class(
"Queue",
public = list(
initialize = function(...) {
for (item in list(...)) {
self$add(item)
}
},
add = function(x) {
private$queue <- c(private$queue, list(x))
invisible(self)
},
remove = function() {
if (private$length() == 0) return(NULL)
# Can use private$queue for explicit access
head <- private$queue[[1]]
private$queue <- private$queue[-1]
head
}
),
private = list(
queue = list(),
length = function() {
base::length(private$queue)
}
)
)
# check = FALSE because of environments
construct(Queue, check = FALSE)
})
})
test_that("R6Class, R < 4.3.0", {
skip_if(with_versions(R >= "4.3.0"))
expect_snapshot({
# example from `?R6::R6Class`
Queue <- R6::R6Class(
"Queue",
public = list(
initialize = function(...) {
for (item in list(...)) {
self$add(item)
}
},
add = function(x) {
private$queue <- c(private$queue, list(x))
invisible(self)
},
remove = function() {
if (private$length() == 0) return(NULL)
# Can use private$queue for explicit access
head <- private$queue[[1]]
private$queue <- private$queue[-1]
head
}
),
private = list(
queue = list(),
length = function() {
base::length(private$queue)
}
)
)
# check = FALSE because of environments
construct(Queue, check = FALSE)
})
})
test_that("R6Class name attribute", {
expect_snapshot({
# the name set by `R6Class()` is not repaired
construct(R6::R6Class("Foo", parent_env = .GlobalEnv), check = FALSE)
construct(R6::R6Class(parent_env = .GlobalEnv), check = FALSE)
# a modified name is
generator <- R6::R6Class("Foo", parent_env = .GlobalEnv)
attr(generator, "name") <- "Bar"
construct(generator, check = FALSE)
})
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.