-
Notifications
You must be signed in to change notification settings - Fork 57
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
'self' triggers 'no visible binding for global variable' #230
Comments
FWIW I don't think you need any workarounds if you define your methods "inline". E.g. here is a simple example: https://github.com/r-lib/progress/blob/master/R/progress.R#L179 |
Hey @gaborcsardi, thanks for coming back to this. I'm working with @James-G-Hill on this one. Might have misunderstood 'inline', if the reprex below isnt inline please do correct me :)
The note and warning is only generated when |
In this case you can put obj_gen <- function(...){
self <- NULL
obj <- R6::R6Class("my_class",
public = list(
... |
That solves it. Its more explicit than: Thanks, |
FYI - same issue for obj_gen <- function(...){
self <- NULL
private <- NULL
obj <- R6::R6Class("my_class",
public = list(
... |
FWIW I'm running into this as well. I define the methods in standalone functions because they are 50+ lines each and inlining them makes an already massive object definition even more so. In my case I cannot include |
IMO think it is not worth getting into active bindings and such, they are fragile in various circumstances. The straightforward way I linked above at #230 (comment) should work better. |
To make sure I understand the approach in the above comment it is roughly this:
e.g. helper <- function(self, private) {
# do stuff
}
my_class <- R6::R6Class(
"my_class",
public = list(
method = function() {
helper(self, private)
}
)
) and as an aside, i'm using active bindings to provide visibility to values of |
The user will always be able to modify |
When defining an R6 object within a package, running 'Check' will cause 'self' to trigger 'no visible binding for global variable' message.
One way to fix it is:
Is there any other solution more targeted to a specific function rather than defined globally?
The text was updated successfully, but these errors were encountered: