[R] Removing objects from workspace
wdunlap at tibco.com
Tue Aug 25 17:21:40 CEST 2009
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Ronggui Huang
> Sent: Monday, August 24, 2009 9:26 PM
> To: Steven Kang
> Cc: r-help at r-project.org
> Subject: Re: [R] Removing objects from workspace
> It depends.
> If there are patterns in the names, you can make use of pattern
> argument of ls(). For example,
> > x1="a";x2="b";x3="c"
> > ls(pattern="x[1-2]")
>  "x1" "x2"
> > ls(pattern="x[^1-2]")
>  "x3"
> # to remove x1-x3
> More generally, if you want to remove all butx,xx,xxx,
> you can use
> >rm(list=ls()[! ls() %in% c(x,xx,xxx)])
You need to quote the x, xx, and xxx. Also,
ls()[ ! ls() %in% c("x","xx","xxx") ]
is the same as the more direct
setdiff( ls(), c("x","xx","xxx") )
TIBCO Software Inc - Spotfire Division
> Hope this helps.
> 2009/8/25 Steven Kang <stochastickang at gmail.com>:
> > Hi all,
> > I am currently woking with hundreds of objects in workspace
> and whenever I
> > invoke ls() to observe the names of the objects, there are
> too much of
> > unnecessary variables.
> > For example, if I only require say 3 or 4 objects from
> hundreds of objects
> > in workspace, are there any methods that may do the job?
> > I have tried rm(-c(x,xx,xxx)), but no luck..
> > Your feedback in this problem would be highly appreciated.
> > Steve
> > [[alternative HTML version deleted]]
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > and provide commented, minimal, self-contained, reproducible code.
> HUANG Ronggui, Wincent
> PhD Candidate
> Dept of Public and Social Administration
> City University of Hong Kong
> Home page: http://asrr.r-forge.r-project.org/rghuang.html
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help