Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R: matching pattern with leading period

I’m using R’s list.files function to pull the full name of a file who’s name matches the following actual characters

   .test_

and has a file extension of xlsx (the full file name is .test_2022-05-23.xlsx).

When I execute the following syntax

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

des <- list.files(path = raw, pattern = "\\.test_.*\\.xlsx$")

, des resolves as character(0).

Apparently the leading

\\.

is not correct?

If I remove the leading period from the actual file’s name and execute the following command

des <- list.files(path = raw, pattern = "test_.*\\.xlsx$")

, des resolves to the expected

test_2022-05-23.xlsx

.

What should I set pattern equal to to match the file’s name when the name begins with a period?

Thanks for your help,

Bill

>Solution :

You should be able to set all.files=T like this:

des <- list.files(path = raw, pattern = "\\.test_.*\\.xlsx$", all.files=T)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading