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

Using named arguments at ... #156

Closed
llrs opened this issue Nov 19, 2019 · 4 comments
Closed

Using named arguments at ... #156

llrs opened this issue Nov 19, 2019 · 4 comments

Comments

@llrs
Copy link

llrs commented Nov 19, 2019

I tried to use the dots in a function and then use the named arguments in glue but I couldn't make it work.

Perhaps this is related to #137 but I couldn't find if it is possible or not.

library("glue")
f <- function(...) {
    print(glue("{a} + {b}"))
    sum(...)
}
f(a = 2, b = 3)
#> Error in eval(parse(text = text, keep.source = FALSE), envir): object 'a' not found

Created on 2019-11-19 by the reprex package (v0.3.0)

I tried some variations with setting other environments but I didn't manage to make it work. Is this behaviour considered for glue?

@jimhester
Copy link
Collaborator

You have to pass the ... to the glue call as well, e.g.

library("glue")
f <- function(...) {
    print(glue("{a} + {b}", ...))
    sum(...)
}
f(a = 2, b = 3)
#> 2 + 3
#> [1] 5

Created on 2019-11-19 by the reprex package (v0.3.0)

@llrs
Copy link
Author

llrs commented Nov 19, 2019

Oh, sorry. Thanks!

@artemklevtsov
Copy link

But you can't nested call.

library("glue")
g <- function(...) {
  f(...)
}
f <- function(...) {
  print(glue("{a} + {b}"))
  sum(...)
}
g(a = 2, b = 3)
# Error in eval(parse(text = text, keep.source = FALSE), envir) : 
#  object 'a' not found

@yutannihilation
Copy link
Member

You have to pass the ... to the glue call, in case you want someone to repeat this for you :)

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

4 participants