styler icon indicating copy to clipboard operation
styler copied to clipboard

Feature request: style chunk options

Open bersbersbers opened this issue 4 years ago • 5 comments
trafficstars

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).

bersbersbers avatar Sep 09 '21 12:09 bersbersbers

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.

lorenzwalthert avatar Sep 10 '21 11:09 lorenzwalthert

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.

bersbersbers avatar Sep 10 '21 12:09 bersbersbers

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 😎

lorenzwalthert avatar Sep 10 '21 13:09 lorenzwalthert

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.

lorenzwalthert avatar Sep 10 '21 13:09 lorenzwalthert

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.

lorenzwalthert avatar Nov 28 '21 20:11 lorenzwalthert

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.

lorenzwalthert avatar Dec 14 '22 07:12 lorenzwalthert