R `scales::comma` 有效但 `scales::comma()` 无效 - 为什么?

Jas*_*ter 0 r scale ggplot2

当我在包中使用函数时,我通常可以将其写成形式function()function不带括号。似乎不是这种情况scales::comma。为什么第 7 行在下面有效,而第 8 行却没有。

library(tidyverse)
mtcars %>% 
  count(cyl) %>% 
  ungroup() %>% 
  mutate(n = n * 1000) %>% 
  ggplot(aes(cyl, n)) + 
  scale_y_continuous(labels = scales::comma) +  # line 7
  # scale_y_continuous(labels = scales::comma()) +  # line 8
  geom_line()
Run Code Online (Sandbox Code Playgroud)

第 8 行错误

Error in number(x = x, accuracy = accuracy, scale = scale, prefix = prefix,  : 
  argument "x" is missing, with no default
Run Code Online (Sandbox Code Playgroud)

Cet*_*ttt 5

这是取自scale_y_continuous有关输入参数的帮助页面labels

标签 之一:

  • NULL 表示没有标签
  • waiver() 用于转换对象计算的默认标签
  • 给出标签的字符向量(必须与中断长度相同)
  • 一个将中断作为输入并返回标签作为输出的函数

在这种情况下,最后一个是重要的。标签需要一个函数scales::commascales::comma()另一方面是该函数返回但不再是函数的内容。