gpt4 book ai didi

r - 为什么 R 不会对我的 tibble : the tale of the dangling comma that could 生气

转载 作者:行者123 更新时间:2023-12-03 20:17:36 26 4
gpt4 key购买 nike

R 希望事情就是这样。命令必须完全正确,而且完全正确。

因此,悬空逗号是不好的。

例如,在向量上:

> c(1,)
Error in c(1, ) : argument 2 is empty

或者一个数据框:
> data.frame(a = 1,)
Error in data.frame(a = 1, ) : argument is missing, with no default.

但由于某种原因而不是在小标题上:
> tibble(a = 1,)
# A tibble: 1 x 1
a
<dbl>
1 1

为什么会这样?什么没了……对吧?

最佳答案

我相信代码有效,因为 tibble() 的参数是使用 rlang::quos() 处理的名称-值对.
quos()有争论 .ignore_empty = c("trailing", "none", "all") .

所以默认为 .ignore_empty是“尾随”——即 tibble 的最后一个参数如果为空,则忽略。如果你改变它,你会看到一个错误:

tibble(a = 1, .ignore_empty = "none",)
Error in eval_tidy(xs[[i]], unique_output) : object '' not found

?tibble?quos详情。

关于r - 为什么 R 不会对我的 tibble : the tale of the dangling comma that could 生气,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52751887/

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