-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
metaprogramming - substitute #873
Comments
Thanks @Polkas. Are you suggesting that the rule that adds Also, this substitution is using base R. {styler} is a tidyverse focussed formatter and there are other (and probably better) tools to do this, namely tidy evaluation. Not sure the problem would occur there too. |
Thank you very much for a quick response. |
Ok, just for the sake of completeness, can you provide a reprex where the current {styler} behavior fails? I.e. changes the result of running the code? |
Reprex, which is showing that finally we get library(magrittr)
FUN_head <- function(x) head(x)
expr <- substitute(airquality %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN_head")))
print(expr)
#> airquality %>% FUN_head()
eval(expr)
#> Ozone Solar.R Wind Temp Month Day
#> 1 41 190 7.4 67 5 1
#> 2 36 118 8.0 72 5 2
#> 3 12 149 12.6 74 5 3
#> 4 18 313 11.5 62 5 4
#> 5 NA NA 14.3 56 5 5
#> 6 28 NA 14.9 66 5 6
styled_expr_str <- styler::style_text('substitute(airquality %>% FUN_EXPR, env = list(FUN_EXPR = call("FUN_head")))')
# double eval as frist one return only result of substitute
styled_expr <- eval(str2lang(styled_expr_str))
print(styled_expr)
#> airquality %>% FUN_head()()
eval(styled_expr)
#> Error in head(x): argument "x" is missing, with no default Created on 2021-12-15 by the reprex package (v2.0.1) |
So, we can solve this when placeholder <- substitute
placeholder(x %>% y, env =list(y = call("head")))
|
I understand this is only a regex rule so my expectancy was not so high. I think an update of the case where the usage of substitute is direct will be more than enough. Thank you once more for the support in this issue. |
- Don't add `()` within substitute piped calls (#873).
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:
The usage of bquote might be a solution here nevertheless substitute is way more efficient:
The text was updated successfully, but these errors were encountered: