Open IndrajeetPatil opened 2 years ago
Thanks. The quick fix I beliebe is just not to use r
at the beginning, as the first unnamed argument of a code chunk header seems to get matched with the engine. In particular for Rcpp:
```{Rcpp}
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
However, to solve this more generically, we should probably rely on {knitr} to parse the code chunk header. This would also allow for https://github.com/r-lib/styler/issues/839, since we'd have keys and values we can easily format. Since we already import {knitr} in Suggests
and everyone working with R Markdown documents already has it, I would be happy to depend on it for this functionality. Not sure {knitr} exports the functionality for parsing the headers, probably not. But maybe we can convince them of that use case. First step would anyways be to find the relevant code in {knitr} that parses the headers. Are you interested in contributing this?
Also note other issues that have been filed with similar requests #832, #312.
First step would anyways be to find the relevant code in {knitr} that parses the headers. Are you interested in contributing this?
Sure, I can try to find the relevant code.
Btw, every time I comment on styler issue, I get this GitHub notification and I have no idea what it's about:
The parameters from chunk header are parsed using an internal function called parse_params()
:
knitr:::parse_params("a=1, engine='Rcpp'")
#> $a
#> [1] 1
#>
#> $engine
#> [1] "Rcpp"
#>
#> $label
#> [1] "unnamed-chunk-3"
knitr:::parse_params("Rcpp, foo, a=1,")
#> $label
#> [1] "Rcpp, foo"
#>
#> $a
#> [1] 1
Created on 2022-03-10 by the reprex package (v2.0.1.9000)
Thanks, I'll file an issue in {knitr} and ask about exporting this function. Really strange these emails you get...
Really strange these emails you get...
This traces to following GHA, which is triggered on issue comment:
strange. Because I never get any e-mail...
Here's all we need to know going forward: https://github.com/yihui/knitr/issues/2112
I also get the e-mails btw
On Thu, Mar 10, 2022 at 3:18 PM Lorenz Walthert @.***> wrote:
Thanks, I'll file an issue in {knitr} and ask about exporting this function. Really strange these emails you get...
— Reply to this email directly, view it on GitHub https://github.com/r-lib/styler/issues/928#issuecomment-1064612666, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2BA5PRWRYZW4VVD3WLST3U7J7KVANCNFSM5QHJ5M2Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
I also get the e-mails btw
@MichaelChirico Do you still get emails when you comment?
This should have been resolved in https://github.com/r-lib/styler/issues/1008.
testing...
In a way, a follow-up to https://github.com/r-lib/styler/issues/312.
Should {styler} ignore {knitr} R code chunk with
Rcpp
engine?For example, if I try to style an
.Rmd
file containing the following chunk,But this file might also contain a number of other R code chunks with
engine = 'R'
, and none of them will be styled due to the offendingRcpp
engine chunk.