I'm sure there is a simple explanation for this, but the brain fog is strong this morning and I'm at a loss. I am trying to use purrr::map() to call a function that sometimes returns an NA, but I keep getting an error message:
"Error: Can't convert a logical vector to function"
Here's a simplified case that returns the error:
library(tidyverse)
test <- function(x){
return(NA)
}
a <- map(.x = 1:2,.f = test())
R classifies NA as a logical variable, but I don't understand why map() is trying to convert this variable to a function when I return it. What am I doing wrong here?
.f = test?test()is a call because you included the parameter delimiters. If you just used its name,testyou might have succeeded. (Once the call got evaluated it returned a logical vector.) The answer to your anthropomorphic question in the title is "because it needed or wanted a function".