gpt4 book ai didi

r - Purrr ~ 操作符记录在哪里?

转载 作者:行者123 更新时间:2023-12-04 11:03:00 25 4
gpt4 key购买 nike

我搜索了 ??"~"但这只能指向 rlang::env_bind (大概是 %<~% )和 base::~ .在 RStudio 中,如何找到 Purrr 的 ~的文档?例如,如果我忘记了如何使用 ~有两个输入,我在哪里看?

最佳答案

给出 AdvanceR 有一个很好的解释(另一个答案中给出的链接)。在 purrr cheatsheat 中还有一个简短的描述(使用示例)。第一页左下角。
enter image description here
twiddle 使用多个参数 ~可以在其不同功能中给出的 purrr 文档中看到。例如map请参阅参数说明,其中指出

.fA function, formula, or vector (not necessarily atomic).If a function, it is used as is.If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:For a single argument function, use .


For a two argument function, use .x and .y


For more arguments, use ..1, ..2, ..3 etc


This syntax allows you to create very compact anonymous functions.



此外,R 在其最新版本 (4.1.0) 中还有 started类似的函数简写符号

R now provides a shorthand notation for creating functions, e.g. \(x) x + 1 is parsed as function(x) x + 1.


这种速记符号也可能在 tidyverse 之外的函数中提供有用的信息,只是与 twiddle 有所不同。因为这里的参数默认没有命名。但同样,当一个不可见函数要在另一个函数中使用时,这种非默认命名也可能被证明是有用的,并且 twiddle在这种情况下,符号样式将不起作用。

关于r - Purrr ~ 操作符记录在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67643144/

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