Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacking data masks? #1779

Closed
mikmart opened this issue Feb 20, 2025 · 4 comments
Closed

Stacking data masks? #1779

mikmart opened this issue Feb 20, 2025 · 4 comments

Comments

@mikmart
Copy link
Contributor

mikmart commented Feb 20, 2025

This is a re-post of this StackOverflow question: https://stackoverflow.com/q/79445476/4550695.

Given a function that defuses its arguments and evaluates them in a data mask:

foo <- function(...) {
  dots <- rlang::quos(...)
  expr <- rlang::quo(list(!!!dots))
  rlang::eval_tidy(expr, list(a = 1))
}

foo(a)
#> [[1]]
#> [1] 1

Is there a way to make a function that wraps the other function and adds another data mask?

A couple of attempts tried and failed:

bar <- function(...) {
  dots <- rlang::quos(...)
  expr <- rlang::quo(foo(!!!dots))
  rlang::eval_tidy(expr, list(b = 2))
}

try(bar(a, b))
#> Error : object 'b' not found
# Looks promising...
bar <- function(...) {
  eval(substitute(foo(...)), list(b = 2), parent.frame())
}

try(bar(a, b))
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2

# ... but fails with injection.
baz <- function(x) {
  bar(a, {{ x }})
}

try(baz(b))
#> Error : object 'b' not found
@lionel-
Copy link
Member

lionel- commented Feb 24, 2025

I don't remember exactly but I don't think so.

@mikmart
Copy link
Contributor Author

mikmart commented Mar 5, 2025

Okay thanks! Is something like this a feature you'd consider supporting?

@lionel-
Copy link
Member

lionel- commented Mar 10, 2025

It doesn't seem like an unreasonable feature but unfortunately it wouldn't be high priority enough to work on this unless this were needed for a tidyverse package.

@mikmart
Copy link
Contributor Author

mikmart commented Mar 10, 2025

That's fair, thanks!

@mikmart mikmart closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants