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

Open
mikmart opened this issue Feb 20, 2025 · 1 comment
Open

Stacking data masks? #1779

mikmart opened this issue Feb 20, 2025 · 1 comment

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.

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