dplyr& r:匿名函数可以加上括号 [英] dplyr & r: Anonymous functions myst be parenthesized
问题描述
我认为我的第一个错误是由于拼写错误而偶然发现的。
I think I've stumbled apon my first error with a spelling mistake.
我正在使用R和dplyr运行以下代码。
I am running the following code with R and dplyr.
> foobar = c(1,2,3)
> foobar %>% as.character
[1] "1" "2" "3"
这很好用,现在我尝试通过匿名函数运行它。
This works fine, now I try to run it through an anonymous function.
> foobar %>% function(x) x * 2
Error: Anonymous functions myst be parenthesized
<知道发生了什么事吗? (并且我需要ping才能将神秘纠正为必须)?
Any idea what is happening? (And where I need to ping to get 'myst' corrected to 'must')?
推荐答案
错误消息非常有用(即使一个单词拼写错误)。
The error message is quite informative (even if one word is misspelled). Put parentheses around the anonymous function.
foobar <- 1:3
foobar %>% (function(x) x * 2)
# [1] 2 4 6
有关说明,请参见
For explanation, see the Using %>% with call- or function-producing rhs section in
help("%>%", "magrittr")
与无关dplyr
。至于错误消息中的错别字,只要您发现可能需要注意的地方,就可以与软件包维护者联系。尽管在此问题已解决 > magrittr
。查找软件包维护者的一种简单方法是使用
It has nothing to do with dplyr
. As for the typo in the error message, whenever you find something that might need attention you can contact the package maintainer. Although it seems this has been fixed in the most recent development version of magrittr
. An easy way to find the maintainer of a package is to use
maintainer("magrittr")
此处省略了结果,因为其中包含电子邮件地址。
The result is omitted here because it contains an email address.
这篇关于dplyr& r:匿名函数可以加上括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!