Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R rm() function on processed code

Tags:

r

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?

like image 647
Nightwriter Avatar asked Jul 15 '26 11:07

Nightwriter


1 Answers

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.

like image 131
MrFlick Avatar answered Jul 20 '26 07:07

MrFlick