Re: [R] wildcards and removing variables

2005-10-10 Thread Marc Schwartz (via MN)
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 [EMAIL PROTECTED] 


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.))

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] wildcards and removing variables

2005-10-10 Thread Johan Sandblom
rm() can take a list of object names as an argument and ls(pattern='^results')
gives such a list. So

rm(ls(pattern='^results'))

would remove all objects that are matched by the regular expression, that is all
that begin with 'results'

HTH, Johan

2005/10/10, Marc Schwartz (via MN) [EMAIL PROTECTED]:
 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 [EMAIL PROTECTED]


 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.))

 HTH,

 Marc Schwartz

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



--
Johan Sandblom  N8, MRC, Karolinska sjh
t +46851776108  17176 Stockholm
m +46735521477  Sweden
What is wanted is not the will to believe, but the
will to find out, which is the exact opposite
- Bertrand Russell

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] wildcards and removing variables

2005-10-10 Thread Gabor Grothendieck
On 10/10/05, Marc Schwartz (via MN) [EMAIL PROTECTED] 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 [EMAIL PROTECTED]


 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*))

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] wildcards and removing variables

2005-10-10 Thread Prof Brian Ripley
On Mon, 10 Oct 2005, Marc Schwartz (via MN) 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 [EMAIL PROTECTED]


 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.))

One new feature of R-2.2.0 is glob2rx, which converts wildcards to regexps 
for you. E.g.

rm(list = ls(pattern = glob2rc(results*)))

(I think if does it a little better, as that trailing dot is not I think 
correct: result* matches result.)

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] wildcards and removing variables

2005-10-10 Thread Roger D. Peng
In R 2.2.0, there is the function 'glob2rx()' which can be used for this 
purpose.  As in

rm(list = ls(pattern = glob2rx(results*)))

-roger

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 [EMAIL PROTECTED] 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

-- 
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] wildcards and removing variables

2005-10-10 Thread Marc Schwartz (via MN)
On Mon, 2005-10-10 at 16:01 +0100, Prof Brian Ripley wrote:
 On Mon, 10 Oct 2005, Marc Schwartz (via MN) 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 [EMAIL PROTECTED]
 
 
  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.))
 
 One new feature of R-2.2.0 is glob2rx, which converts wildcards to regexps 
 for you. E.g.
 
 rm(list = ls(pattern = glob2rc(results*)))
 
 (I think if does it a little better, as that trailing dot is not I think 
 correct: result* matches result.)

Thanks to both Gabor and Prof. Ripley for pointing out the use of
glob2rc(). One of the new features I had forgotten about since reading
NEWS.

On the trailing dot, I was just in the process of drafting a follow up
after realizing my error, since as you point out, 'results' would not be
matched in that case.

Thanks,

Marc

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html