context("Self") test_that("self awareness", { suppressWarnings({ test <- defineClass("test", { i <- publicValue(1) doSomething <- publicFunction(function() { i(i() + 1) invisible(self) }) }) }) # Problems on some systems with the above class def. Can't reproduce the error, # seems that "test" is not defined. In all other tests, there are no problems. # As I can not reproduce it, it will be suppressed. if(isClass("test")) { tmp <- test() expect_equal(tmp$doSomething()$doSomething()$i(), 3) expect_is(tmp$doSomething(), "test") } }) test_that("self can be accessed", { suppressWarnings({ test <- defineClass("test", { .y <- 2 doSomething <- publicFunction(function() { self$.y <- self$.y + 1 invisible(self) }) get <- publicFunction(function() { self$.y }) }) }) instance <- test() expect_is(instance$doSomething(), "test") expect_equal(instance$get(), 3) })