Obtaining exact pattern in list.files()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtaining exact pattern in list.files()

Bogaso
Hi,

In the list.files() function, there is an argument 'pattern' to locate the
desired files. However I failed to see if I can manage to fetch those files
that having an exact match.

For example, if there are 2 files that contain the expression 'File' and
'Second_File', then I should get the 1st one. However R is returning both
the files.

Any pointer on how to achieve that would be helpful. Thanks,

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Obtaining exact pattern in list.files()

Ista Zahn
pattern = "^File$"

Best,
Ista
On Wed, Sep 12, 2018 at 7:53 AM Christofer Bogaso
<[hidden email]> wrote:

>
> Hi,
>
> In the list.files() function, there is an argument 'pattern' to locate the
> desired files. However I failed to see if I can manage to fetch those files
> that having an exact match.
>
> For example, if there are 2 files that contain the expression 'File' and
> 'Second_File', then I should get the 1st one. However R is returning both
> the files.
>
> Any pointer on how to achieve that would be helpful. Thanks,
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Obtaining exact pattern in list.files()

Jeff Newmiller
In reply to this post by Bogaso
Study regular expressions via ?regex or any of the many websites you can find with a search engine. With no special characters, your search pattern matches anywhere in the string. Start your study by learning about the ^ and $ characters.

On September 12, 2018 4:53:09 AM PDT, Christofer Bogaso <[hidden email]> wrote:

>Hi,
>
>In the list.files() function, there is an argument 'pattern' to locate
>the
>desired files. However I failed to see if I can manage to fetch those
>files
>that having an exact match.
>
>For example, if there are 2 files that contain the expression 'File'
>and
>'Second_File', then I should get the 1st one. However R is returning
>both
>the files.
>
>Any pointer on how to achieve that would be helpful. Thanks,
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.