rvisual-studio-codelintrtargets-r-package

No visible global function definition/no visible binding for global variable in a project?


I'm working with R in VS Code, using the R Extension. I do almost all of my project work using targets, which means that my package imports and functions are usually in separate files.

A simple example would be working in a folder which looks like

project
│   packages.R
│   README.md
│   _targets.R
│
├───R
│       functions.R

The problem I have is that I get warnings from {lintr} for global function definitions for functions (esp specials) loaded from packages.R (or from tar_option_set(packages=c(...))). I have a similar problem with lintr not recognising column names, instead thinking of them as missing variables. For example, a function in functions.R might look like:

Example of lintr warnings

If I was developing a package, the solution (as posted here and elsewhere) would be to include the function in the NAMESPACE. But I don't feel like every quick analysis requires a package. How else do I avoid these warnings? Is the only other option to exclude these linters in /.lintr?


Solution

  • You could disable the object usage linter in your project. Example: https://github.com/ropensci/targets/blob/8c42336a228874889c9ee99dd154c567b4eee91a/.lintr#L4. More on linters: https://github.com/r-lib/lintr#available-linters