r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
405 stars 56 forks source link

Throw error if field does not exist? #123

Closed hadley closed 4 years ago

hadley commented 7 years ago
X <- R6Class("X")
x <- X$new()

x$X

Why isn't this an error?

wch commented 7 years ago

For the same reason this isn't an error:

e <- new.env()
e$x
# NULL

Changing the behavior would require adding a $.R6 method, but it would add a significant performance penalty.

hadley commented 7 years ago

Oh, right, I keep forgetting that we can't have a $ method 😞

hadley commented 7 years ago

It occurs to me that we might be able to make this fast by using object tables. Worth at least a small exploration.

hadley commented 4 years ago

object tables turn out to be fairly slow, so unlikely to be worth it.