Here is a function that has a bug:
f_with_arg <- function(an_argument) {
# Oops! Object a_bug does not exist
this_is <- a_bug
}
If I call this function with an integer argument, I get a very sensible error message:
> f_with_arg(0)
Error in f_with_arg(0) : object 'a_bug' not found
But if I call it with a string, I get a non-sensical error message:
> f_with_arg("a_string")
Error in f_with_arg("a_string") : object '"a_string"' not found
Is this expected? It makes it hard to find my typos (of which I make many!).
Curiously, a list that doesn't have a string does what one would expect, while a list with a string produces the same problematic error message:
> f_with_arg(list(foo=1))
Error in f_with_arg(list(foo = 1)) : object 'a_bug' not found
> f_with_arg(list(foo=1, bar="a_string"))
Error in f_with_arg(list(foo = 1, bar = "a_string")) :
object '"a_string"' not found
It's been many moons since I've been mystified by R like this. Can you please help me understand?
Thank you,
-John