Skip to content
Prev 388555 / 398513 Next

ls() pattern question

Thanks Andrew. it works well. --- Kai
On Wednesday, July 14, 2021, 05:22:01 PM PDT, Bert Gunter <bgunter.4567 at gmail.com> wrote:
Actually fun( param != something..) is syntactically incorrect in the first place for any function! 

ls sees "pat != whatever"? as the "name" argument of ls() and can't make any sense of it, of course. 
 
Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Wed, Jul 14, 2021 at 5:01 PM Andrew Simmons <akwsimmo at gmail.com> wrote:
Hello,


First, `ls` does not support `!=` for pattern, but it's actually throwing a
different error. For `rm`, the objects provided into `...` are substituted
(not evaluated), so you should really do something like

rm(list = ls(pattern = ...))

As for all except "con", "DB2", and "ora", I would try something like

setdiff(ls(), c("con", "DB2", "ora"))

and then add `rm` to that like

rm(list = setdiff(ls(), c("con", "DB2", "ora")))

On Wed, Jul 14, 2021 at 7:41 PM Kai Yang via R-help <r-help at r-project.org>
wrote:
? ? ? ? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.