I would like to check if an R environment exists, but the standard exists() function doesn't accept an environment as argument:
storage <- new.env(parent = emptyenv())
storage
#<environment: 0xeb3195c>
exists(storage)
#Error in exists(storage) : invalid first argument
Is there any way of checking if an environment has been defined? Or is it an intrinsically wrong thing to do? Thanks!
exists
takes a character argument:
exists("storage")
Though note that this will return TRUE
even if storage
is not an environment. You will either have to check it using is.environment
as Señor O suggests, or pass mode="environment"
:
exists("storage", mode="environment")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With