Skip to content

pretty_rmd overwrites all lines of chunk with first line in Rmd with single chunk #68

@yogat3ch

Description

@yogat3ch

Reprex:

file.create("test.Rmd")
writeLines('
---
title: "Untitled"
output: html_document
---
```{r, cache = F, echo = F}
library(htmltools)
if (isTRUE(getOption("knitr.in.progress"))) {
  message("I am knitting")
tagList(
  div(id = "include-iframeResizer"),
  htmlDependency(
    name = "iframeResizer",
    version = "4.2.8",
    src = c(href = "https://cdn.jsdelivr.net/npm/iframe-resizer@4.2.8/js/",
            file = "inst"),
    script = "iframeResizer.contentWindow.min.js",
    all_files = F
    )
)
}

```', con = "test.Rmd")

sinew::pretty_rmd("test.Rmd", output = NULL, open_output = FALSE, create_library = FALSE)

Output is:

---
title: "Untitled"
output: html_document
---
```{r, cache = F, echo = F}
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
library(htmltools)
```

The bug is related to pretty_rmd.R#158 mapply simplifying to matrix when there's just one chunk.

This makes it such that pretty_rmd.R#L167 copies the first line to all lines.

Fixed by #67 by adding SIMPLIFY = FALSE to prevent simplification of output from mapply on an Rmd with a single chunk to an array/matrix.

Does not appear to be an issue when create_library = TRUE and pretty_rmd_library is used instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions