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
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,
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
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
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:
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,
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,
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,
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 -
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
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
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
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
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,
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
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
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
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
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:
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
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
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
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
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
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
25 matches
Mail list logo