-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Convert chunk option to YAML #2151
Conversation
Possible by considering R expression using !expr
Tests are failing because r-forge seems down... and some examples uses it. |
and donttest does not seem to prevent that because of a CRAN check flag it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect. Thanks!
R/parser.R
Outdated
params3, handlers = list( | ||
# true / false instead of no | ||
logical = function(x) { | ||
result <- ifelse(x, "true", "false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think simply tolower(x)
would work. Correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes you're right it should work woth the automatic logical to character conversion.
This close #2082 and follows #2149
Chunk options are parsed and then written to YAML using
yaml::as.yaml()
with two tweaks to the parsed chunk optionstrue
orfalse
instead of defaultyes
orno
!expr
to make the fact they should be evaluted before parsing. Example:will be converted to
Doing
is a bit more complicated than the current solution, as it implies going through the all tree of expression to only find the leaf is list that are variable or expression to evaluated with
!expr
This solution is simple enough to produce valid document, and it is easy enough for the user to reformat manually some chunk header.
Here is how a conversion looks like on all knitr-examples: yihui/knitr-examples@master...cderv:knitr-examples:yaml-chunk-header
Does it seems right to you ?
It seems there is still an indent question where the chunk header is not indented, whereas the code inside is - do we want to indent the in-chunk option part too.
Anyway, @yihui I let you review. I wanted to have something ready for the conference, so here it is.