styler
styler copied to clipboard
Feature request: style chunk options
bug.Rmd:
```{r, a=b,c =d}
message("Hi!")
```
> styler::style_file("bug.Rmd")
Styling 1 files:
/home/berker/iTReX/inst/rmd/bug.Rmd ✔
────────────────────────────────────────
Status Count Legend
✔ 1 File unchanged.
ℹ 0 File changed.
✖ 0 Styling threw an error.
────────────────────────────────────────
It would be great if the chunk options could be styled to
```{r, a=b, c=d}
message("Hi!")
```
(note the spaces).
Maybe, if they are parsable R code we could do that. Note that people can have unparsable headings, such as
```{r, if=b, c=d}
message("Hi!")
```
And therefore, we had #832.
I see, thanks for the explanation. I wasn't even aware that this could be parseable R code - I had always just seen these as simple key-value pairs separated by commas.
Well it’s not parsable, I added c( and ) to it to make it parsable. That way, it was easier to find the keys. Now, I’d tue argument has key=value, we might be fooled 😎
Approach would be to parse if possible, then style that character vector with styler and return it. I’d not parsable, use the workaround in #832.
The reason why we understood them as parsable R code first (wrapped between c( and )) is because then, we don't have to deal with quoting, which can occur in the keys and or values.
I think this is out of scope. Also, for quarto docs, it seems the syntax with comments inline is preferred anyways, so I guess that will decrease in relevance.