-
Notifications
You must be signed in to change notification settings - Fork 188
Description
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:
- 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.