Skip to content

no visible binding for global variable ‘Cloaked’ #336

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

Closed
bnsh opened this issue Jul 9, 2018 · 5 comments
Closed

no visible binding for global variable ‘Cloaked’ #336

bnsh opened this issue Jul 9, 2018 · 5 comments
Labels
bug an unexpected problem or unintended behavior object linters 🏀

Comments

@bnsh
Copy link

bnsh commented Jul 9, 2018

Hi. I'm sure that this is a misunderstanding of mine, since I'm not really an R programmer...

I have my code here: https://gist.github.com/bnsh/3839c4eb2c6b31e32c39ec312014b2b8

#! /usr/bin/env Rscript

library(R6)

Cloaked <- R6Class("Cloaked",
  public = list(
    msg = function() {
      return(paste(
        "this code _works_, but lintr (https://github.com/jimhester/lintr) complains that",
        "external.R:6:8: warning: no visible binding for global variable ‘Cloaked’",
        "when I try to use Cloaked within a function.",
        "It's fine tho, if I use it _outside_ a function."
      ))
    }
  )
)

main <- function() {
  c <- Cloaked$new()
  c$msg()
}

main()

It works... But, lintr complains: "cloak.R:19:8: warning: no visible binding for global variable ‘Cloaked’"

Why? What do I have to do to satisfy lintr?

Thanks!

@jimhester
Copy link
Member

There isn't really anything to do, this is the expected behavior. You can either turn off the object linter or use #nolint on that line.

@bnsh
Copy link
Author

bnsh commented Jul 15, 2018

Thanks @jimhester ! (I didn't know if it was a real problem, and that just doing '#nolint start' / '#nolint end' would just mask the problem...)

Is this a similar issue then? (It complains about "no visible global function definition for 'cloaked'..)

 #! /usr/bin/env Rscript

cloaked <- function() {
  return(paste(
    "this code _works_, but lintr (https://github.com/jimhester/lintr)",
    "complains that external.R:13:3: warning: no visible global function",
    "definition for ‘cloaked’ when I try to use cloaked within a function.",
    "It's fine tho, if I use it _outside_ a function."
  ))
}

main <- function() {
  cloaked()
}

main()

Is that also expected behavior?

Thanks!

@jimhester
Copy link
Member

Yes, that is expected.

@infotroph
Copy link
Contributor

Can you say more about why this example is expected when #27 isn't? I don't follow whether this is a parsing limitation or if I missed a memo that using locally-defined functions is bad practice.

@jimhester
Copy link
Member

It is expected in that it is a known issue, ideally this would be fixed, but it requires changing how the files are processed and the object linter is structured.

@russHyde russHyde added the bug an unexpected problem or unintended behavior label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior object linters 🏀
Projects
None yet
Development

No branches or pull requests

4 participants