Skip to content

metaprogramming - substitute #873

Closed
@Polkas

Description

@Polkas

I will be glad if you consider to support one of the metaprogramming scenario.
Unfortunately I find out quite dangerous side effect of styler styling.

Example where we will expect the styler to NOT add brackets in %>% pipeline:

styler::style_text('substitute(DATA %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN")))')
# substitute(DATA %>% FUN_EXPR(), env = list(FUN_EXPR = call("FUN")))
# whereas should be neutral
# substitute(DATA %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN")))

The usage of bquote might be a solution here nevertheless substitute is way more efficient:

> microbenchmark::microbenchmark(bquote = {bquote(x <- .(letters))}, substitute = {substitute(x <- ll, list(ll = letters))})
#Unit: nanoseconds
#       expr  min   lq    mean median     uq   max neval cld
#     bquote 4387 4510 4809.71   4592 4674.0 24313   100   b
# substitute  164  246  281.67    246  266.5  2378   100  a 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions