Skip to content

Instantly share code, notes, and snippets.

@DominikRafacz
Created July 25, 2022 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikRafacz/e54cc8d3626f14c5de6f6038b8d09645 to your computer and use it in GitHub Desktop.
Save DominikRafacz/e54cc8d3626f14c5de6f6038b8d09645 to your computer and use it in GitHub Desktop.
Curious matching fun case
fun_wants_num <- function(x) {
x + 1
}
fun_wants_fun_but_fails <- function(fun) {
fun(1)
}
fun_wants_fun <- function(fun) {
fun <- match.fun(fun)
fun(2)
}
g09 <- function(x, ...) {
exp(x)
}
g10 <- function() {
g09 <- 10
print(g09 + 3) # used as a value
print(g09(3)) # used as a function
print(fun_wants_num(g09)) # used as a value
print(fun_wants_fun(g09)) # used as a function
print(fun_wants_fun_but_fails(g09)) # used as a value - error!
}
g10()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment