Skip to content

Lint fails with Rmd chunks using {lang} engine format #322

@cnolanminich

Description

@cnolanminich

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:

  1. attempt to lint the chunk and throw an error for the user
  2. 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:

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions