You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lintr:::get_source_expressions fails when a code comment contains an r script command surrounded by backticks #879
We were surprised our files linted correctly despite having obvious linting issues, so I have investigated and narrowed it down to this minimal reprex:
# `r print("7")`function() 2<=3
The above doesn't lint.
I further narrowed the issue down to backticks in combination with r and something because the following do lint correctly:
# `print("7")`function() 2<=3# `r`function() 2<=3# r print("7")function() 2<=3
In short - all three are needed: backticks, r and something in addition to r.
Then, I dug inside inflix_spaces_linter and tracked the issue to the parsing function, Given a file "test.R", lintr:::get_source_expressions("test.R") returns:
Without the comment, it parses correctly:
@MichaelChirico any starting points if we want to give it a look re: overhaul? For us this issue is quite a problem since we use the lifecycle package and therefore have this basically everywhere ...
Try and find out how knitr decides if a file is Rmd or not, perhaps there's an exported function we could re use. otherwise, we might try running parse() first and if that fails, check if the file is Rmd
Activity
MichaelChirico commentedon Oct 20, 2021
I believe it's a duplicate of #743
kpagacz commentedon Oct 21, 2021
Do you know of any workaround?
MichaelChirico commentedon Oct 21, 2021
sadly no... the detection logic for Rmd is too greedy. Needs an overhaul but it was quite messy when I tried to take a quick look at fixing it.
danielinteractive commentedon Oct 22, 2021
@MichaelChirico any starting points if we want to give it a look re: overhaul? For us this issue is quite a problem since we use the
lifecyclepackage and therefore have this basically everywhere ...MichaelChirico commentedon Oct 22, 2021
Try and find out how knitr decides if a file is Rmd or not, perhaps there's an exported function we could re use. otherwise, we might try running parse() first and if that fails, check if the file is Rmd
danielinteractive commentedon Oct 23, 2021
@MichaelChirico cool thx!
@kpagacz do you want to have a look at it maybe with Michael's ideas?