Skip to content

Chunk option attr-output in R chunks does not add attribute to html  #5456

Closed

Description

@ateucher

Bug description

Adding the attr-output option in an R chunk has no effect on the rendered html (i.e., the attribute does not get added).

Reprex:

```{r}
#| error: true
#| warning: true
#| message: true
#| attr-output: "style='color: blue;'"
#| attr-error: "style='color: yellow;'"
#| attr-warning: "style='color: orange;'"
#| attr-message: "style='color: green;'"
#| results: asis
cat("something")
stop("something")
warning("something")
message("something")
```

image

Quarto check:

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.340
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.6
      Path: /Library/Developer/CommandLineTools/usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.0
      Path: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources
      LibPaths:
        - /Users/andyteucher/Library/R/arm64/4.3/library
        - /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
      knitr: 1.42
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
  • Please provide the output of quarto check so we know which version of quarto and its dependencies you're running.

Activity

  1. added
    bug
    on May 8, 2023
  2. added
    upstream
    on May 8, 2023
  3. added
    triaged-to
    on May 8, 2023
  4. mcanouil commented on May 8, 2023

    @mcanouil
    Collaborator

    FYI, I opened an issue upstream since the behaviour is the same using rmarkdown, see yihui/knitr#2256.

  5. added
    engines-knitr
    on May 8, 2023
  6. cderv commented on May 9, 2023

    @cderv
    Member

    @ateucher let me put also here the answer I give upstream at yihui/knitr#2256 (comment) but using Quarto example

    This is just happening in your example because you are using results: asis

    This means no code chunk output will be created by knitr to put the attributes on. It will be output asis in the resulting document. So that is expected for this specific usage.

    See this example showing the difference

    ---
    title: "Demo"
    format: html
    keep-md: true
    ---
    
    ```{r}
    # Set global option
    knitr::opts_chunk$set(attr.output = "style='color: blue;'")
    ```
    
    ```{r}
    #| results: asis
    cat("something")
    ```
    
    ```{r}
    cat("something")
    ```
    
    

    image

    And intermediate source code
    ---
    title: "Demo"
    format: html
    keep-md: true
    ---
    
    
    ::: {.cell}
    
    ```{.r .cell-code}
    # Set global option
    knitr::opts_chunk$set(attr.output = "style='color: blue;'")
    ```
    :::
    
    
    ```{.r .cell-code}
    cat("something")
    ```
    
    something
    
    ::: {.cell}
    
    ```{.r .cell-code}
    cat("something")
    ```
    
    ::: {.cell-output .cell-output-stdout}
    ```{style='color: blue;'}
    something
    ```
    :::
    :::
    

    There is no issue here - just an unexpected usage of attr.output. For message, error and warning, asis does not apply so that is why you get the correct wrapping in .md file with correct class.

    I'll look closer at your original slack message for the original issue with out-extra

  7. removed
    triaged-to
    on May 9, 2023
  8. removed
    bug
    on May 9, 2023
  9. mcanouil commented on May 11, 2023

    @mcanouil
    Collaborator

    In Quarto, being able to add attributes other than class allows to use many things, such as tooltip, hover effect, aria-, etc. to a code cell.
    I am not sure it would be really complex to add such things, unless you want to notify the user he/she is doing nonsense html thing, and even if that's the case Pandoc will basically prepend data- to the whole value of attributes which in the end should be harmless.

    Source: yihui/knitr#2256 (comment)

    To continue on discussing the possible addition of attributes alongside classes as a more general approach (not tied up to knitr) to add any kind of attributes (including classes) on code cells.

  10. cderv commented on May 11, 2023

    @cderv
    Member

    @mcanouil Le'ts create a specific feature request for this with some example on expected results and why it would be useful. This issue is initially about a related problem but not directly to this idea of yours. I think that would be easier to track.

  11. mcanouil commented on May 11, 2023

    @mcanouil
    Collaborator

    True, I hesitated.
    Although this issue itself seems "resolved", isn't it? ("close as not planned")

  12. cderv commented on May 11, 2023

    @cderv
    Member

    Yes exactly, if you open a new one , I'll close this one.

  13. mcanouil commented on May 17, 2023

    @mcanouil
    Collaborator

    I am closing this as resolved.

    For discussion about the global code cell attributes option feature request, see #5587

  14. added
    support
    on Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

engines-knitrsupportupstream

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions