To be correct for the regular expression, it should be:
dir(pattern = "\\.(txt|doc)$")
The form
dir(pattern="*.txt")
will match 'txt' appearing anywhere in the name; this looks like the
argument you would have used to "Sys.glob" which is a UNIX style file
name match and not a regular expression
Do you wish to include .docx files as well or just .doc?
Michael
On Wed, Dec 21, 2011 at 10:04 AM, Alaios wrote:
> Dear all
> I would like to ask from dir function in R (?dir)
> to give me only the files that end with .txt or .doc.
>
> The dir functions supports the use of patterns (is not that
>From the help for dir:
File naming conventions are platform dependent. The pattern
matching works with the case of file names as returned by the OS
On my linux system, this works:
> dir(pattern="*.txt")
[1] "a.txt" "b.txt"
>
> dir(pattern="*.doc")
[1] "c.doc"
>
> dir(pattern="*.doc|*
Dear all
I would like to ask from dir function in R (?dir)
to give me only the files that end with .txt or .doc.
The dir functions supports the use of patterns (is not that regular
expressions) for doing that.
print(dir(i,full.names=TRUE,pattern=.))
Could you please help me compose such a
Thanks to everyone who contributed to my questions. As ever, I am extremely
grateful to all those on the R-list who make it what it is.
Regards
Mike Griffiths
On Tue, Nov 15, 2011 at 5:47 PM, Joshua Wiley wrote:
> Hi Michael,
>
> Your strings were long so I made a bit smaller example. Sarah ma
Hi Michael,
Your strings were long so I made a bit smaller example. Sarah made
one good point, you want to be using gsub() not sub(), but when I use
your code, I do not think it even works precisely for one instance.
Try this on for size, you were 99% there:
## simplified cases
form1 <- c('produ
Hi Michael,
You need to take another look at the examples you were given, and at
the help for ?sub():
The two ‘*sub’ functions differ only in that ‘sub’ replaces only
the first occurrence of a ‘pattern’ whereas ‘gsub’ replaces all
occurrences. If ‘replacement’ contains backreferen
Good afternoon list,
I have the following character strings; one with spaces between the maths
operators and variable names, and one without said spaces.
form<-c('~ Sentence + LEGAL + Intro + Intro / Intro1 + Intro * LEGAL +
benefit + benefit / benefit1 + product + action * mean + CTA + help + me
8 matches
Mail list logo