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
This issue is related to #32, where lintr should ignore non-R chunks as it lints. lintr currently only ignores chunks that have the following chunk header: {r engine = "LANG"}, vs. the newer and now more common {LANG} Refer here, and the discussion on knitr issue #963here.
Currently, if you use the {LANG} language engine syntax, lintr will do 2 things:
attempt to lint the chunk and throw an error for the user
not lint any R code after that chunk.
Below is a minimal reprex, using the .Rmd test case in lintr as a base and adding a chunk with {python}.
text <- c('# Test #
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
```{r}
a = 1
```
Test
====
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
```{r}
b <- function(x) {
d = 1
}
```
```{r engine="python"}
a=[]
a[0]=1
```
```{python}
a=[]
a[0]=1
```
## Same code chunk as above, but lintr will not ouput this
```{r}
b <- function(x) {
d = 1
}
```
')
tmp <- tempfile()
writeLines(text, tmp)
lintr::lint(tmp)
The results of the lint are below:
The part of the code that would require an edit is here.
I think the fix to this would involve adding another && condition that checked that the chunk began with r and does NOT have engine following it. Or perhaps more simply, found any chunk that began with anything other than r and ignored it. Happy to try a fix on this and submit a PR if that would be useful.
The text was updated successfully, but these errors were encountered:
Rmarkdown format allows the use of code blocks in the following format
```{some_engine}
# not necessarily R syntax
foo = bar
```
These blocks should be filtered out before linting the remaining R-code blocks.
A couple of python blocks were added to test.Rmd: one with R-like syntax and one with syntax that can't be parsed as R.
The function `defines_knitr_engine` was extracted from `extract_r_source` and extended. This tests for the presence of {r engine = some_engine} and {some_engine} in the start line of a code chunk. The names of valid engines are obtained from `knitr::knit_engines`
This issue is related to #32, where lintr should ignore non-R chunks as it lints.
lintr
currently only ignores chunks that have the following chunk header:{r engine = "LANG"}
, vs. the newer and now more common{LANG}
Refer here, and the discussion on knitr issue #963 here.Currently, if you use the
{LANG}
language engine syntax,lintr
will do 2 things:Below is a minimal reprex, using the .Rmd test case in
lintr
as a base and adding a chunk with{python}
.The results of the lint are below:
The part of the code that would require an edit is here.
I think the fix to this would involve adding another
&&
condition that checked that the chunk began withr
and does NOT haveengine
following it. Or perhaps more simply, found any chunk that began with anything other thanr
and ignored it. Happy to try a fix on this and submit a PR if that would be useful.The text was updated successfully, but these errors were encountered: