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

R files generating knitr templates are parsed as Rmd #743

Closed
MichaelChirico opened this issue Feb 10, 2021 · 3 comments · Fixed by #1407
Closed

R files generating knitr templates are parsed as Rmd #743

MichaelChirico opened this issue Feb 10, 2021 · 3 comments · Fixed by #1407
Labels
bug an unexpected problem or unintended behavior

Comments

@MichaelChirico
Copy link
Collaborator

If I have a file that generates knitr templates, e.g.

writeLines('
CreateTemplate <- function(x) {
return(sprintf("
```{r code}
foo <- function(x) x+%d
foo(5)
```", x))
}', tmp <- tempfile())

parse(tmp) works just fine, however, lintr assumes this is an Rmd based on matching some chunk regex:

lintr::lint(tmp)
# /tmp/RtmpN8X7Dj/file3d0536f05e5d:4:1: error: Missing chunk end for chunk (maybe starting at line 4).
# ```{r code}
# ^

Should we try parsing the file as R code first, then checking Rmd chunks afterwards?

@AshesITR
Copy link
Collaborator

Or maybe check for valid YAML front matter to detect Rmd?

@MichaelChirico
Copy link
Collaborator Author

the front matter might also be part of a template, so we'll have to force it to come at the top of the file (perhaps following whitespace)...
is there any requirement for Rmd to have YAML? i.e. is it possible to knit an Rmd that only uses some defaults?

@AshesITR
Copy link
Collaborator

Not entirely sure, but IINM a YAML front matter starting at line 1 is required (or at least present in 99.999% of Rmd scripts)

I suggest taking a look at knitrs code base. IIRC it has a parse front matter function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants