Question: Its possible to create a function taking a "logical expression" argument as the [subset function](https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf#page.510) does?

For instance, something like this working:

```
x <- function(d, s)
{
  # ...
  return(subset(d, s))
}

```

Where `d` is a data.frame and `s` is a R logical expression

Answer: 
One approach is doing it just like `subset()` (you can see `subset()` code by `getS3method("subset", "data.frame")` and my answer is a piece of the code). `eval(expr, envir)` evaluates the `expr` argument in the environment specified by `envir`.

```
x <- function(d, s) {
  r <- eval(substitute(s), d)
  return(d[r,])
}

a1 <- x(iris, Species == "virginica")
a2 <- x(iris, Species == "virginica" & Sepal.Length > 7)
b <- x(cars, dist > 50)

```
One way would be to use a combination of `eval` and `parse`:

```
x <- function(d, s) {
  return(subset(d, eval(parse(text = s))))
}

high.temp <- x(d = airquality, s = "Temp > 80")

```