-
Notifications
You must be signed in to change notification settings - Fork 73
style R Markdown (code chunks) #13
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
Comments
Could we use knitr to parse the .Rmd file? The Not sure about styling plain text, realistically we'd need to parse and write back Markdown. |
As far as I know, there is only the |
knitr is not supposed to test it, just to do the extraction work for us (determine what is code, what language is that code in, what is text). |
Thanks @jimhester for that hint. I just tried out the function and it indeed seems to me that we could use it to achieve our goal. @krlmlr I found the exported function |
Inline R code is typically a single statement long, so likely does not have anything worth linting / styling. Supporting it would complicate the implementation for limited gain. We do use internal knitr functionality https://github.com/jimhester/lintr/blob/aa70430282852afa15a61cc69771e71dd32e1aec/R/extract.R#L40-L41, to detect the code boundries. The reason you can't use purl et all directly is they transform the source code lines into a new script, so the line numbers do not match the original version. For the linting case we simply blank out the non-R lines and lint that file, you would have to do something more complicated for styler. |
I'd say closed with #233 for now. Styling markdown text is out of scope I think. The only thing one might consider is formatting to 80 characters (for non-code). We could integrate |
Question: how is this supposed to work? I tried to style the file at https://gist.github.com/tvatter/25dbb789b64e7ba9484c65b5d4c4f828
(and obviously the ugly code chunk was left untouched) |
Oh gosh, my bad.... the code is in text... Forget it :) |
Uh oh!
There was an error while loading. Please reload this page.
It would be nice if styler could not only format plain .R files, but also .Rmd files.
Code Chunks
This could probably by implemented by changing
transform_files
, i.e. adding a functiontransform_lines_rmd_chunk
. Main steps are:read read_lines_enc
^´´´\\{r.*\\} *$
and^``` *$
write_lines_enc
@krlmlr maybe this functionality fits even in the
utf8
package?Plain Text
. , ? !
ect.)The second point might be out of the scope of the package though...
The text was updated successfully, but these errors were encountered: