冒号等于R中的运算符?新语法?

colons equals operator in R? new syntax?

在阅读 http://ggvis.rstudio.com/interactivity.html 时,我注意到代码中有 := 散落在其中。我假设这是一种为函数提供参数的新方法?具体是什么?

mtcars %>%
  ggvis(~wt, ~mpg, size := input_slider(10, 1000)) %>%
  layer_points(fill := "red") %>%
  layer_points(stroke := "black", fill := NA)

在这种情况下,:= 只是 ggvis 用于分配固定值的语法;相反,= 在这里用于分配变量值。正如您在代码示例中可能已经注意到的那样,在右侧,只有 "red" 或 NA 这样的值,因此 := 是在此上下文中使用的正确运算符。例如,如果您希望 "size" 依赖于 "mpg" 列,您可以使用通常的等号编写 size = mpg

我承认我对:=不够熟悉,所以说是否还有其他包也采用了这个运算符。

From http://ggvis.rstudio.com/properties-scales.html (see for further examples and information):

"The props() function uses the = operator for mapping (scaled), and the := operator for setting (unscaled). It also uses the ~ operator to indicate that an expression should be evaluated in the data (and in ggvis, the data can change); without the ~ operator, the expression is evaluated immediately in the current environment. Generally speaking, you’ll want to use ~ for variables in the data, and not use it for constant values."