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

False positives with lintr on package that uses rcpp #591

Closed
3 of 5 tasks
pschloss opened this issue Sep 11, 2024 · 2 comments
Closed
3 of 5 tasks

False positives with lintr on package that uses rcpp #591

pschloss opened this issue Sep 11, 2024 · 2 comments

Comments

@pschloss
Copy link

Before filing a bug

  • I have installed the latest dev version of {precommit} with remotes::install_github('lorenzwalthert/precommit')
  • I have installed the latest hook revisions (update with precommit::autoupdate())
  • I have installed the latest release of the upstream Python framework pre-comit as described under the update instructions.

Describe the bug

My R package has internal Rcpp code that is called within a user-facing R function. When I run lintr::lint_package() everything passes. When I commit changes to the *.R file, the lintr hook fails. In the output below, addition() is a file written with {Rcpp}. {Rcpp} was added to the package with usethis::use_rcpp()

$ git commit -m "Trigger precommit hook"
style-files..............................................................Passed
use-tidy-description.................................(no files to check)Skipped
spell-check..............................................................Passed
lintr....................................................................Failed
- hook id: lintr
- exit code: 1

File `R/hello.R` is not lint free
/Users/pschloss/Desktop/test/R/hello.R:8:3: warning: [object_usage_linter] no visible global function definition for 'addition'
  addition(c(1, 2, 3))
  ^~~~~~~~
Error: File R/hello.R is not lint free
Execution halted


readme-rmd-rendered..................................(no files to check)Skipped
parsable-R...............................................................Passed
no-browser-statement.....................................................Passed
no-print-statement.......................................................Passed
no-debug-statement.......................................................Passed
deps-in-desc.............................................................Passed
pkgdown..............................................(no files to check)Skipped
check for added large files..............................................Passed
file contents sorter.................................(no files to check)Skipped
fix end of files.........................................................Passed
check pre-commit.ci config...........................(no files to check)Skipped
Don't commit common R artifacts......................(no files to check)Skipped

To Reproduce
A minimal package is available here. It is the default package generated from RStudio with {Rcpp} and {precommit} loaded. There is an additional file, addition.cpp in src/. It runs as expected and passes the build check.

Expected behavior
Running lintr::lint_package() passes without any issues. I'd expect the same when running the pre-commit hook

Additional context

  • My operating system is: Mac OS X
  • My project uses {renv}.
  • the output of packageVersion('renv')
@lorenzwalthert
Copy link
Owner

Thanks. The reason is that your package won't be devtool::load_all() so object_usage_linter won't work always it seems as explained in #440. Workarounds also there.

@pschloss
Copy link
Author

Thanks! This solution by @joelnitta did the trick for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants