You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I know, there is only the knitr code chunk option tidy that tidies up the output based on formatR, but I don't know how knitr could tidy the source.
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.
I know its a minor thing but I just thought about inline R code in Rmd documents. It would be nice if that could also be covered, but I think this is not the case with extract_r_code, right?
Also, what was the reason against using (internal) knitr functionality in the lintr package to do the extraction, as @krlmlr suggests?
@krlmlr I found the exported function knitr:pulr(text = character_vec) that returns all code lines (not only R) as a character vector, but I think this does not really help us. I just had a quick look at internal functions of knitr, and probably there are tools that could help us, but I did not really have time yet to explore that further.
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.
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 stylermd into styler (i.e. copying relevant code over). If you @jonmcalder are interested, you can have a look, otherwise we leave it for now.
Activity
krlmlr commentedon May 14, 2017
Could we use knitr to parse the .Rmd file? The
transform_lines_enc()function in utf8 seems generic enough.Not sure about styling plain text, realistically we'd need to parse and write back Markdown.
lorenzwalthert commentedon May 14, 2017
As far as I know, there is only the
knitrcode chunk optiontidythat tidies up the output based onformatR, but I don't know howknitrcould tidy the source.krlmlr commentedon May 14, 2017
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).
jimhester commentedon May 16, 2017
We do this in lintr, https://github.com/jimhester/lintr/blob/aa70430282852afa15a61cc69771e71dd32e1aec/R/extract.R
lorenzwalthert commentedon May 18, 2017
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.
I know its a minor thing but I just thought about inline R code in Rmd documents. It would be nice if that could also be covered, but I think this is not the case with
extract_r_code, right?Also, what was the reason against using (internal)
knitrfunctionality in thelintrpackage to do the extraction, as @krlmlr suggests?@krlmlr I found the exported function
knitr:pulr(text = character_vec)that returns all code lines (not only R) as a character vector, but I think this does not really help us. I just had a quick look at internal functions of knitr, and probably there are tools that could help us, but I did not really have time yet to explore that further.jimhester commentedon May 18, 2017
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.
lorenzwalthert commentedon Oct 13, 2017
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
stylermdinto styler (i.e. copying relevant code over). If you @jonmcalder are interested, you can have a look, otherwise we leave it for now.tvatter commentedon Jun 6, 2019
Question: how is this supposed to work?
I tried to style the file at https://gist.github.com/tvatter/25dbb789b64e7ba9484c65b5d4c4f828
using
styler::style_file("sample.Rmd")and I got:(and obviously the ugly code chunk was left untouched)
tvatter commentedon Jun 6, 2019
Oh gosh, my bad.... the code is in text... Forget it :)
Merge pull request #13 from r-lib/fix-braces-in-function-calls