将包含空格的列名传递给自定义函数内的 filter_()

Passing a column name containing spaces to filter_() inside a custom function

任何人都可以告诉我如何让这样的功能工作:

library(tidyverse)
## Testing Data:
dat  <- tibble(without_space=rep(c(0,1),5), `with space`=rep(c(1,0),5))
## Some custom function containing filter:
custom_filter  <- function(data, column, value){
    return(filter_(data, column==value))
}
## Expected Output:
filter(dat, `with space`==0)

## Function Call:
custom_filter(dat, `with space`, 0)

我阅读了一些关于标准和非标准评估的资料,并尝试了 as.name()quote() 等,但无法正常工作。

感谢您的帮助!

尝试:

library(tidyverse)

custom_filter  <- function(data, column, value) {

  return(filter(data, !! enquo(column) == value))

}