2

I want to be able to determine if an argument to a function is a call to a function or not. Lets say I have two functions , f() and g():

f <- function() "foo" 

g <- function(x){
  ???
} 

I want the output to the calls as below:

g(f())
#> [1] TRUE
g("bar")
#> [1] FALSE

I can get this to work by quoting the function arguments:

f <- function() "foo" 

g <- function(x) is.call(x)

g(quote(f()))
#> [1] TRUE
g(quote("bar"))
#> [1] FALSE

However this is sub-optimal as I don't want users of the function to have to do this. Any suggestions?

dave-edison
  • 3,666
  • 7
  • 19

1 Answers1

4

You can use substitute():

h <- function(x) is.call(substitute(x))
h(f())
# [1] TRUE
duckmayr
  • 16,303
  • 3
  • 35
  • 53