【发布时间】:2019-07-23 04:25:43
【问题描述】:
我有以下函数,它只是连接一系列字符串
test_func <- function(cellTypeA, cellTypeB, other_text) {
paste(cellTypeA, " ", cellTypeB, " ", other_text)
}
我有一组参数打包成一个小标题。
param_df <- structure(list(cellTypeA = c("Cluster11", "Cluster2", "Cluster4"
), cellTypeB = c("Cluster11", "Cluster2", "Cluster4")), row.names = c(NA,
-3L), class = "data.frame")
看起来像这样:
cellTypeA cellTypeB
1 Cluster11 Cluster11
2 Cluster2 Cluster2
3 Cluster4 Cluster4
我想使用 purrr::pmap 在上面设置的参数上迭代函数。但是为什么这不起作用呢?
library(tidyverse)
param_df %>%
pmap(~test_func(.cellTypeA, .cellTypeB, "FOO"))
它给了我:
Error in cat(cellTypeA, " ", cellTypeB) : object '.cellTypeA' not found
我希望结果如下所示:
[[1]]
[1] Cluster11 Cluster11 FOO
[[2]]
[1] Cluster2 Cluster2 FOO
[[3]]
[1] Cluster4 Cluster4 FOO
【问题讨论】: