Re: [R] Extracting File Basename without Extension

2009-01-14 Thread William Dunlap
The S+ basename() function has an argument called suffix and it will remove the suffix from the result. This was based on the Unix basename command, but I missed the special case in the Unix basename that doesn't remove the suffix if the removal would result in an empty string. The suffix must

Re: [R] Extracting File Basename without Extension

2009-01-11 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: On Fri, Jan 9, 2009 at 4:20 PM, Wacek Kusnierczyk right; there's a straightforward fix to my solution that accounts for cases such as '.bashrc': names = c(foo.bar, .zee) sub((.+)[.][^.]+$, \\1, names) you could also use a lookbehind if possible (not in r,

Re: [R] Extracting File Basename without Extension

2009-01-11 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote: On Fri, Jan 9, 2009 at 4:28 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Rau, Roland wrote: P.S. Any suggestions how to become more proficient with regular expressions? The O'Reilly book (Mastering...)? Whenever I tried anything more

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Berwin A Turlach
G'day all, On Fri, 9 Jan 2009 08:12:18 -0200 Henrique Dallazuanna www...@gmail.com wrote: Try this also: substr(basename(myfile), 1, nchar(basename(myfile)) - 4) Or, in case that the extension has more than three letters or myfile is a vector of names: R myfile - path1/path2/myoutput.txt R

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Berwin A Turlach wrote: G'day all, On Fri, 9 Jan 2009 08:12:18 -0200 Henrique Dallazuanna www...@gmail.com wrote: Try this also: substr(basename(myfile), 1, nchar(basename(myfile)) - 4) Or, in case that the extension has more than three letters or myfile is a vector of names:

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Gabor Grothendieck
On Fri, Jan 9, 2009 at 6:52 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Berwin A Turlach wrote: G'day all, On Fri, 9 Jan 2009 08:12:18 -0200 Henrique Dallazuanna www...@gmail.com wrote: Try this also: substr(basename(myfile), 1, nchar(basename(myfile)) - 4) Or,

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
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,

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Berwin A Turlach
G'day Wacek, On Fri, 09 Jan 2009 12:52:46 +0100 Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Berwin A Turlach wrote: G'day all, On Fri, 9 Jan 2009 08:12:18 -0200 Henrique Dallazuanna www...@gmail.com wrote: Try this also: substr(basename(myfile), 1,

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Berwin A Turlach wrote: G'day Wacek, Or, in case that the extension has more than three letters or myfile is a vector of names: R myfile - path1/path2/myoutput.txt R sapply(strsplit(basename(myfile),\\.), function(x) R paste(x[1:(length(x)-1)], collapse=.)) [1] myoutput R myfile2 -

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Berwin A Turlach
G'day Wacek, On Fri, 09 Jan 2009 14:22:19 +0100 Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Apparently also a possibility, I guess it can be made to work with the original example and my extensions. i guess it does work with the original example and your

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Berwin A Turlach wrote: G'day Wacek, On Fri, 09 Jan 2009 14:22:19 +0100 Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Apparently also a possibility, I guess it can be made to work with the original example and my extensions. i guess it does work with the

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Prof Brian Ripley wrote: Actually, that's a valid regex in any of the variants offered. A more conventional writing of it is the second of f - 'foo.bar.R' sub([.][^.]*$, , f) [1] foo.bar sub(\\.[^.]*$, , f) [1] foo.bar more conventional in r, perhaps. it's not portable, due to the

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Berwin A Turlach
G'day Wacek, On Fri, 09 Jan 2009 15:19:46 +0100 Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: i think i did not suggest the original poster to learn perl. As I see it, you didn't suggest anything to the original poster, at least not directly. But, since these days you have to

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Henrique Dallazuanna
Right, Other option is: substr(nameFile, 1, tail(unlist(gregexpr(\\., nameFile)), 1) - 1) On Fri, Jan 9, 2009 at 1:23 PM, Rau, Roland r...@demogr.mpg.de wrote: Hi, [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Try this also: substr(basename(myfile), 1,

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Duncan Murdoch
On 1/8/2009 9:10 PM, Gundala Viswanath wrote: Dear all, The basename() function returns the extension also: myfile - path1/path2/myoutput.txt basename(myfile) [1] myoutput.txt Is there any other function where it just returns plain base: myoutput i.e. without 'txt' I'm curious about

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Rau, Roland
Hi, [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Try this also: substr(basename(myfile), 1, nchar(basename(myfile)) - 4) This, of course, assumes that the extensions are always 3 characters. Sometimes there might be more (index.html), sometimes less

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Gabor Grothendieck
On Fri, Jan 9, 2009 at 10:23 AM, Rau, Roland r...@demogr.mpg.de wrote: Hi, [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Try this also: substr(basename(myfile), 1, nchar(basename(myfile)) - 4) This, of course, assumes that the extensions are always 3

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Peter Dalgaard
Duncan Murdoch wrote: On 1/8/2009 9:10 PM, Gundala Viswanath wrote: Dear all, The basename() function returns the extension also: myfile - path1/path2/myoutput.txt basename(myfile) [1] myoutput.txt Is there any other function where it just returns plain base: myoutput i.e. without

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Marc Schwartz
on 01/09/2009 09:00 AM Duncan Murdoch wrote: On 1/8/2009 9:10 PM, Gundala Viswanath wrote: Dear all, The basename() function returns the extension also: myfile - path1/path2/myoutput.txt basename(myfile) [1] myoutput.txt Is there any other function where it just returns plain base:

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: I'm curious about something: does file extension have a standard definition? Most (all? I haven't tried them all) of the solutions presented in this thread would return an empty string for the plain base if given the filename .bashrc. right; there's a

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Wacek Kusnierczyk
Rau, Roland wrote: P.S. Any suggestions how to become more proficient with regular expressions? The O'Reilly book (Mastering...)? Whenever I tried anything more complicated than basic usage (things like ^ $ * . ) in R, I was way faster to write a new function (like above) instead of finding

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Gabor Grothendieck
On Fri, Jan 9, 2009 at 4:20 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Duncan Murdoch wrote: I'm curious about something: does file extension have a standard definition? Most (all? I haven't tried them all) of the solutions presented in this thread would return an

Re: [R] Extracting File Basename without Extension

2009-01-09 Thread Gabor Grothendieck
On Fri, Jan 9, 2009 at 4:28 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Rau, Roland wrote: P.S. Any suggestions how to become more proficient with regular expressions? The O'Reilly book (Mastering...)? Whenever I tried anything more complicated than basic usage (things

[R] Extracting File Basename without Extension

2009-01-08 Thread Gundala Viswanath
Dear all, The basename() function returns the extension also: myfile - path1/path2/myoutput.txt basename(myfile) [1] myoutput.txt Is there any other function where it just returns plain base: myoutput i.e. without 'txt' - Gundala Viswanath Jakarta - Indonesia

Re: [R] Extracting File Basename without Extension

2009-01-08 Thread jim holtman
You can use 'sub' to get rid of the extensions: sub(^([^.]*).*, \\1, 'filename.extension') [1] filename sub(^([^.]*).*, \\1, 'filename.extension.and.more') [1] filename sub(^([^.]*).*, \\1, 'filename without extension') [1] filename without extension On Thu, Jan 8, 2009 at 9:10 PM, Gundala