【发布时间】:2021-11-24 11:14:46
【问题描述】:
下面我的foo 函数效果很好,但是它省略了与其矢量输出相关的名称。
对于下面的示例,我希望 foo 返回:
scale
[1] 2
但它只是返回:
[1] 2
有解决办法吗?
library(tidyverse)
library(rlang)
txt = "
study scale
1 1
1 1
2 2
3 2
3 2
3 2
4 1
"
h <- read.table(text = txt,h=T)
foo <- function(data, ...){
dot_cols <- rlang::ensyms(...)
str_cols <- purrr::map_chr(dot_cols, rlang::as_string)
min(sapply(str_cols, function(i) length(unique(data[[i]]))))
}
foo(h, study, scale)
【问题讨论】:
标签: r function dplyr tidyverse rlang