[R] wildcards and removing variables
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Oct 10 17:00:03 CEST 2005
On 10/10/05, Marc Schwartz (via MN) <mschwartz at mn.rr.com> wrote:
> On Mon, 2005-10-10 at 10:37 -0400, Afshartous, David wrote:
> > All,
> >
> > Is there are a wildcard in R for varible names as in unix? For example,
> >
> > rm(results*)
> >
> > to remove all variable or function names that begin w/ "results"?
> >
> > cheers,
> > Dave
> > ps - please respond directly to afshar at miami.edu
>
>
> See ?ls, which has a 'pattern' argument, enabling the use of Regex to
> define the objects to be listed and subsequently removed using rm().
>
> You can then use something like:
>
> rm(list = ls(pattern = "\\bresults."))
Also, in R 2.2.0 (or look in sfsmisc package for older versions of R)
you can use glob2rx to get shell-style wildcards (aka globbing):
ls(pattern = glob2rx("results*"))
More information about the R-help
mailing list