gpt4 book ai didi

r - R 3.4.4 和 R 3.5 中 deparse 的不同结果

转载 作者:行者123 更新时间:2023-12-04 18:20:22 24 4
gpt4 key购买 nike

deparse在 R 3.4.4 和 R 3.5 中产生不同的结果。 NEWS建议一些默认设置已更改,但我不清楚如何确保 deparse在 R 3.4.4 和 R 3.5 中产生相同的输出

3.4.4

> deparse(list(dec = 4L, b = "a"), control = "keepNA")
[1] "list(dec = 4, b = \"a\")"

3.5
> deparse(list(dec = 4L, b = "a"), control = "keepNA")
[1] "list(4, \"a\")"

编辑:

感谢@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)

最佳答案

我还没有安装 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. On the other hand, without deparse options "showAttributes" and "niceNames", names are no longer shown also for lists. as.character(list( c (one = 1))) now includes the name, as as.character(list(list(one = 1))) has always done.

关于r - R 3.4.4 和 R 3.5 中 deparse 的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50422627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com