Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yogat3ch opened this issue Nov 11, 2020 · 0 comments

Comments

@yogat3ch
Copy link
Contributor

yogat3ch commented Nov 11, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant