[英]Different results from deparse in R 3.4.4 and R 3.5
deparse
produces different results in R 3.4.4 and R 3.5. deparse
在R 3.4.4和R 3.5中产生不同的结果。 The NEWS suggests some defaults settings have changed but it is not clear to me how to ensure deparse
produces the same output in R 3.4.4 and R 3.5 新闻提示某些默认设置已更改,但我不清楚如何确保
deparse
在R 3.4.4和R 3.5中产生相同的输出
R 3.4.4 R 3.4.4
> deparse(list(dec = 4L, b = "a"), control = "keepNA")
[1] "list(dec = 4, b = \"a\")"
R 3.5 R 3.5
> deparse(list(dec = 4L, b = "a"), control = "keepNA")
[1] "list(4, \"a\")"
EDIT: 编辑:
Thanks to helpful suggestions by @HongOoi and @akrun the closest thing to a solution that will ensure the same result in both R 3.4.4 and R 3.5 seems to be: 感谢@HongOoi和@akrun的有用建议,最接近解决方案的是确保R 3.4.4和R 3.5中的相同结果似乎是:
dctrl <- if (getRversion() > "3.4.4") c("keepNA", "niceNames") else "keepNA"
deparse(list(dec = 4L, b = "a"), control = dctrl)
I haven't got R 3.5 installed, but per the NEWS file, you could try the showAttributes
and/or niceNames
arguments to deparse
: 我没有安装R 3.5,但根据NEWS文件,您可以尝试使用
showAttributes
和/或niceNames
参数来deparse
:
These functions gain a new control option "niceNames" (see .deparseOpts()), which when set (as by default) also uses the (tag = value) syntax for atomic vectors.
这些函数获得了一个新的控制选项“niceNames”(参见.deparseOpts()),当设置时(默认情况下)也使用原型向量的(tag = value)语法。 On the other hand, without deparse options "showAttributes" and "niceNames", names are no longer shown also for lists.
另一方面,如果没有deparse选项“showAttributes”和“niceNames”,则列表也不再显示名称。 as.character(list( c (one = 1))) now includes the name, as as.character(list(list(one = 1))) has always done.
as.character(list(c(one = 1)))现在包含名称,因为as.character(list(list(one = 1)))总是这样做。
We could use substitute
in R 3.5
to get the same result as in R 3.4.4
我们可以在
R 3.5
使用substitute
来获得与R 3.4.4
相同的结果
deparse(substitute(list(dec = 4L, b = "a")), control = "keepNA")
#[1] "list(dec = 4, b = \"a\")"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.