[R] excluding on element from a list

Daisy Englert Duursma daisy.duursma at gmail.com
Tue May 25 01:46:24 CEST 2010

Thanks for your help and for the info on the website. I did not know
what to call regular expressions and so I could not search for them.

On Mon, May 24, 2010 at 7:08 PM,  <Richard.Cotton at hsl.gov.uk> wrote:
>> I am making a list of all the files in a folder and I want to exclude
>> one file called "proj.current".  This is the 31st file in a folder.
>> Currently I use the command:
>> tdirs <- list.files(pattern="proj.")[-31]
>> However I would like to exclude it based on its name and not the
> position.
> You need to update the pattern in the regular expression to look for
> strings beginning with "proj.", but not having "current" afterwards.
> My first thought was to use perl style regular expressions, but apprently
> this isn't supported.
> tdirs <- list.files(pattern = "proj\\.(?!current)", perl=TRUE)   #Throws
> error
> Instead, you're probably better off doing it in two steps.
> tdirs <- list.files(pattern="proj\\.")
> tdirs <- tdirs[tdirs != "proj.current"]
> Notice the difference between "proj." and "proj\\.".  The first means
> 'proj followed by any character', and the second means 'proj followed by a
> dot'.  See http://www.regular-expressions.info/quickstart.html for more
> info on regexes.
> Regards,
> Richie.
> Mathematical Sciences Unit
> ------------------------------------------------------------------------
> This message contains privileged and confidential information intended
> for the addressee(s) only. If this message was sent to you in error,
> you must not disseminate, copy or take any action in reliance on it and
> we request that you notify the sender immediately by return email.
> Opinions expressed in this message and any attachments are not
> necessarily those held by the Health and Safety Laboratory or any person
> connected with the organisation, save those by whom the opinions were
> expressed.
> Please note that any messages sent or received by the Health and Safety
> Laboratory email system may be monitored and stored in an information
> retrieval system.
> ------------------------------------------------------------------------
> Think before you print - do you really need to print this email?
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> Scanned by MailMarshal - Marshal's comprehensive email content security
> solution. Download a free evaluation of MailMarshal at www.marshal.com
> ------------------------------------------------------------------------

Daisy Englert Duursma

Room E8C156
Dept. Biological Sciences
Macquarie University  NSW  2109

Tel +61 2 9850 9256

10A Carrington Rd
Hornsby, NSW 2077

Mobile: 0421858456

More information about the R-help mailing list