[R] Extracting File Basename without Extension

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jan 9 13:31:17 CET 2009


Gabor Grothendieck wrote:
> On Fri, Jan 9, 2009 at 6:52 AM, Wacek Kusnierczyk
>
>   
>> or have sub do the job for you:
>>
>> filenames.ext = c("foo.bar", basename("foo/bar/hello.dolly"))
>> (filenames.noext = sub("[.][^.]*$", "", filenames.ext, perl=TRUE))
>>     
>
> We can omit perl = TRUE here.
>
>   


or maybe not, depending on the actual task:

names = replicate(10000, paste(sample(c(letters, "."), 100,
replace=TRUE), collapse=""))
system.time(replicate(10, sub("[.][^.]*$", "", names, perl=TRUE)))
system.time(replicate(10, sub("[.][^.]*$", "", names)))

vQ




More information about the R-help mailing list