Let me explain with the help of an example.
I have two functions :
fun1 <- function(x) {
assertthat::assert_that(is.numeric(x), msg = 'Not a number')
x
}
fun2 <- function(x) {
assertthat::assert_that(x > 10, msg = 'Number not greater than 10')
x + 10
}
They are called one into another.
fun1(x = fun2(20))
#[1] 30
However, if fun2
fails, I get message from fun1
.
fun1(x = fun2(2))
Error: Not a number
I would expect to get message from fun2
itself which is 'Number not greater than 10'
.
How can I get that?
I know I can break down the function calls like below which will resolve my issue.
y <- fun2(20)
fun1(x = y)
but this is a simplified example. In my real case, it is not possible to do this nor do I want to do it in that way.
Any ideas?