-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when making generator a method of an R6 class #30
Comments
Maybe there should be a way of preventing R6 from treating a function as a method? For example functions wrapped in Relatedly, maybe What do you think @wch? |
In the meantime you can wrap the generators like this @dfalbel R6::R6Class(
"generator",
private = list(
generators = list(x = coro::generator(function() {
for (i in 1:10)
yield(i)
}))
),
public = list(
x = function() private$generators$x()
)
) |
Thanks! That works great for me! |
With R6 does have the notion of members function that are not methods, though. They must be assigned either in num_generator <- coro::generator(function() {
for (i in 1:10)
yield(i)
})
Generator <- R6::R6Class(
"Generator",
public = list(
initialize = function() {
self$x = num_generator
},
x = NULL
)
) (You could also call The difference between methods and non-method functions is recognized when the object is cloned; in the cloned object, methods will have their environment changed (so they can find the correct @lionel-, the idea of using |
Thanks for your input @wch! Closing this since it's not a coro issue. |
Not sure if you want to support that, but the following does not work:
R6 changes the function environments to the class env. It's probably also removing important information from the generator function.
The text was updated successfully, but these errors were encountered: