:=
包含don't deparse
nicely的表达式:
call1 <- quote(f(a = b(c = d)))
call2 <- quote(f(a := b(c := d)))
# nice
deparse(call1)
#> [1] "f(a = b(c = d))"
# not nice
deparse(call2)
# [1] "f(`:=`(a, b(`:=`(c, d))))"
我想从call2
:获得以下输出"f(a := b(c := d))"
。
我正在寻找一种在所有情况下都可以解析:=
的通用解决方案。=
<-
一种解决方法
<<-
此解决方法使用具有相似或相同优先级且不经常使用的事实。我在原始调用中替换:=
为 by <<-
,然后它很好地解析,然后我gsub
返回到:=
. 不过,我想要一个干净而通用的解决方案。
gsub("<<-",":=", deparse(do.call(
substitute, list(call2, list(`:=` = quote(`<<-`))))))
#> [1] "f(a := b(c := d))"