how to apply not exists function in r inside sapply

I was using this exists function to see if an object is in my environment or not. However, when I apply !exists inside the sapply, it throws an error. Does anyone know why this is happening?
code is below

x <- c(2,3,4)
y <- c(5,6,9)
any(sapply(c("x", "y"), exists)) # it works but
any(sapply(c("x", "y"), !exists)) # not working

Thank you!
best,
adr

I think the problem is that !exists is not a function. This does not throw an error

x <- c(2,3,4)
y <- c(5,6,9)
any(sapply(c("x", "y"), function(thing) !exists(thing)))
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.