Skip to content

Skip eval=FALSE chunks? #581

Closed
Closed

Description

@MichaelChirico

I want to use undesirable_function_operator to block install.packages on some files (where package installation should be handled by a build tool rather than in the script itself), however, it is common for Rmd scripts to include instructions on setting up the environment to reproduce the output that includes install.packages in an eval=FALSE cell.

I would like to skip linting in such cases -- what's the best way to go about this? An option to skip eval=FALSE Rmd cells in lintr::lint and lintr::get_soure_expressions?

Example:

writeLines('
```{r install, eval = FALSE}
install.packages("lintr")
```
', tmp <- tempfile(fileext = ".Rmd"))
lintr::lint(tmp, lintr::undesirable_function_linter(c(install.packages= "")))

Activity

  1. AshesITR commented on Nov 23, 2020

    @AshesITR
    Collaborator

    What would we do about knitr::opts_chunk$set(eval = FALSE)?

    I think your usecase might better be served by replacing the eval = FALSE chunks by regular souce code chunks with r syntax highlighting using ```r.

  2. added
    feature
    on Dec 9, 2020
  3. MichaelChirico commented on Dec 15, 2020

    @MichaelChirico
    CollaboratorAuthor

    @AshesITR I think you're right we won't be able to get a complete static solution. But checking explicit chunk options would still be an improvement.

  4. russHyde commented on May 17, 2021

    @russHyde
    Collaborator

    Ran into a similar problem while writing a blogpost that mingles R<4.1 code/env with R-4.1 code:

    ```{r eval = FALSE}
    # R 4.1.0 code (but using in an R-4.0.5 environment)
    rnorm(100) |>
      density() |>
      plot()
    ```
    

    "Error: unexpected '>'"


    Note that when rewriting this to use 'quoted'-code block syntax, the lintr fails with a Malformed file error (which is a much bigger problem IMO)

    ```r
    rnorm(100) |>
      density() |>
      plot()
    ```
    
    "Error: Malformed file!"
    

    Similarly, if I add a CSS-class to the quoted-code block, but don't add an evaluation engine (ie, I'll style this myself, since autoformatting isn't working, and eval=FALSE won't bypass the code), the file is Malformed:

    ```{.r}
    rnorm(100) |>
      density() |>
      plot()
    ```
    

    "Error: Malformed file!"

  5. AshesITR commented on Jun 19, 2022

    @AshesITR
    Collaborator

    The "malformed file" error should be fixed now, so closing this as using

    ```r
    rnorm(100) |>
      density() |>
      plot()
    ```
    

    Should be the (preferable) way to achieve syntax highlighting without evaluation.

  6. MichaelChirico commented on Jun 19, 2022

    @MichaelChirico
    CollaboratorAuthor

    I'm not sure this is fully solved ... but please open a new issue if there's still need for improvement here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions