Skip to content
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

global variables not found? #27

Closed
randy3k opened this issue Dec 29, 2014 · 17 comments
Closed

global variables not found? #27

randy3k opened this issue Dec 29, 2014 · 17 comments
Labels
bug an unexpected problem or unintended behavior object linters 🏀

Comments

@randy3k
Copy link
Collaborator

randy3k commented Dec 29, 2014

screen shot 2014-12-29 at 12 17 19 am

Script global variables should be detected, but they are not.

SublimeLinter: r output:
/var/folders/w9/7w10svxj5093z4831n7m27w00000gp/T/SublimeLinter3-randy/untitled.lintr:8:5: warning: no visible global function definition for ‘foo’, Did you mean 'for'?
    foo(y) + increment
    ^~~
/var/folders/w9/7w10svxj5093z4831n7m27w00000gp/T/SublimeLinter3-randy/untitled.lintr:8:14: warning: no visible binding for global variable ‘increment’
    foo(y) + increment
             ^~~~~~~~~ 
@jimhester
Copy link
Member

This is an unfortunate side effect from switching to parsing each top-level expression separately (so that each expression can be cached separately) rather than parsing the whole file at once.

If you are developing a package lintr will include of the symbols in the package namespace as globals (you just need to install some version of the in-development package).

This should get fixed though, thanks for opening the issue.

@randy3k
Copy link
Collaborator Author

randy3k commented Dec 30, 2014

Hi Jim,

Thanks for the quick response. I forgot to thank you for this amazing package. I have been looking for a comprehensive R linting package for a while until I discovered this.

I work with R script files most of the time. It would be great if lintr can handle script global variables correctly.

One more thing: I tried to turn off the cache function, it reports the same lint results.

@jimhester jimhester added the bug an unexpected problem or unintended behavior label Jan 12, 2015
@jimhester
Copy link
Member

Need to tweak logic at R/object_usage_linter.R#L8-L19 to evaluated the current file and include the top level names.

@KDr2
Copy link

KDr2 commented Apr 8, 2016

Is someone working on this? or I can disable some linter to avoid this?
Thanks

@jimhester
Copy link
Member

You can disable the object_usage_linter to avoid it.

fvafrCU added a commit to fvafrCU/cleanr that referenced this issue Oct 24, 2016
broke test ny trying to trick my way through lintr, I now use .lintr and the and
exlusion tags. lintr has some issue
(r-lib/lintr#27).
@galadude
Copy link

galadude commented Nov 2, 2016

I'm having this problem aswell. Can you tell me how to disable object_usage_linter?

@user01
Copy link

user01 commented Nov 11, 2016

@galadude You can set the used linters when calling lint. For example:

lintr::lint_package(linters=lintr::default_linters[-14])

I checked names(lintr::default_linters), "found object_usage_linter" index, and removed it for the lint.

@fangly
Copy link
Contributor

fangly commented Mar 6, 2017

I am also having "no visible global function definition for 'bakName'" and "no visible binding for global variable for global variable 'test'" lints, though, they only happen in my "tests/testthat/helper_utils.R" file:

test <- new.env()


bakName <- function(funName, envir) {
  paste0(environmentName(envir), "_", funName, ".bak")
}

overwriteFunction <- function(oldFun, newFun, envir=baseenv()) {
  assign(bakName(oldFun, envir), get0(oldFun, envir = envir), envir = test)
  assign(oldFun, newFun, envir = envir)
}

My "R/*" files do not generate it, and neither do my "tests/testthat/test*.R" files.

@bcipolli
Copy link

Any sense of priority on this? The linter complains about functions defined within the same file, not being found; this seems pretty basic.

Disabling the linting check ... defeats the purpose of having a linter. It's a critical check for a linter to do.

It's been almost 3 years; can anything be done to bump up the priority on this? I'm not sure my R chops are up to snuff to tackle this one..

rflprr added a commit to datadotworld/dwapi-r that referenced this issue Nov 21, 2017
rflprr added a commit to datadotworld/dwapi-r that referenced this issue Nov 22, 2017
* Address compatibility issues with testthat 2.0.0
* Work aroud issue r-lib/lintr#27
nuest added a commit to nuest/o2r-inspecter that referenced this issue Dec 20, 2017
@leonelgalan
Copy link

I'm very new to R, so I'm not sure if this is the same issue but doing:

library(bar)
foo <- bar()

Give me a "no visible global function for bar, did you mean 'x'?" This code works, this library, defines the function, is just a lintr issue.

Is the key still in https://github.com/jimhester/lintr/blob/master/R/object_usage_linter.R#L8-L19 like suggested by @jimhester? He said "to evaluated the current file and include the top level names.", any one has pointers of where to get started?

@tsikerdekis
Copy link

tsikerdekis commented Jan 5, 2019

An update on the exclusion strategy. It is better to remove by name than by index position:

lintr::lint_package(linters=subset(lintr::default_linters,!lintr::default_linters %in% lintr::default_linters["object_usage_linter"] ))

@mnist91
Copy link

mnist91 commented Oct 14, 2022

I still encounter this issue when running lint-checks on github workfows. The very own functions of the package are not found by lintr. Has anyone solved this issue rather than disabling the object_usage_linter?

@MichaelChirico
Copy link
Collaborator

Hi @mnist91, please open a new issue with an example if you're able.

FYI, search around other issues with the same 'object linters' tag first, it might solve your issue. if so, still feel free to open a documentation request if you think that can be improved. Thanks!

@alice-hannah
Copy link

@mnist91 did you ever find a solution to this problem? I can't find any other issues that seem to address this.

@AshesITR
Copy link
Collaborator

Hi @alicebyers5, if you are developing a package, installing the package prior to linting will eliminate all object usage warnings related to symbols in the package namespace.
There is a documentation issue to track alerting users of this quirk.

@allefeld
Copy link

The same happens with variables which only exist within a data frame, within pipelines using e.g. mutate or pivot_wider.

@zachmayer
Copy link

Hi @alicebyers5, if you are developing a package, installing the package prior to linting will eliminate all object usage warnings related to symbols in the package namespace. There is a documentation issue to track alerting users of this quirk.

Installing the package prior to linting fixed this for me, thank you!

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