Whats with rm()? I can remove an object using a string, but it seems that a processing resulting in a string does not work:
obj <- "my.obj"
o.str <- "obj.test"
class(sub("[.]test","",o.str)) # "character"
class("obj") # "character"
identical(sub("[.]test","",o.str),"obj") # "TRUE"
rm("obj") # works
obj <- "my.obj"
rm(sub("[.]test","",o.str))
# error:
# Error in rm(sub("[.]test", "", o.str)) :
# ... must contain names or character strings
why?
The better way to remove values with a given character string is via the list= argument
rm(list=sub("[.]test","",o.str))
The way the "..." is documented is that it expects the objects as either quoted or unquoted names. It doesn't expect a function that will return names. That's what list= is for.
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