[R] Extracting File Basename without Extension
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jan 9 15:19:46 CET 2009
Berwin A Turlach wrote:
> G'day Wacek,
>
> On Fri, 09 Jan 2009 14:22:19 +0100
> Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at 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 extensions.
>>
>
> And I thought that you would have known for sure.....
>
i thought i did until you made that comment, which made me think you've
just discovered it doesn't.
>
>>> Though, it seems to require the knowledge of perl, or at least
>>> perl's regular expression.
>>>
>> oh my, sorry. it' so bad to go an inch out of the cosy world of r.
>>
>
> Well, if that's how you feel, don't do it.
>
quite the opposite.
> I regularly use other languages besides R. Mostly C and Fortran,
> occasionally Python. But I never found time to learn Perl or Java or
> awk or C++ or....; some people do not have the time to learn all
> languages under the sun. Also, if one concentrates on a few, one can
> learn them really well.
>
i think i did not suggest the original poster to learn perl.
many responses on this list involve regular expressions, and regexes are
so ubiquitous in code that has to do with parsing and processing text,
be it filenames or loads of data, that a user of r may well want to
learn a bit of this stuff in addition to the details about how real
numbers are represented below the surface.
you may want to keep saying 'use r where applicable instead of worse
tools', and i'd like to keep saying 'use regexes where they're
applicable instead of worse tools'. same philosophy.
>
>> but, as gabor pointed, 'perl=TRUE' is inessential here,
>>
>
> I thought that your answer to Gabor indicated that, depending on the
> context, perl=TRUE was essential; though I must admit that I did not
> run that code.
>
i see i may have expressed that wrongly. it should have been "but maybe
you'd want to keep it", meaning this is not essential for the final
result, but may improve the runtime.
>
>> so you actually need to know just (very basic) regular expressions,
>> with no 'perl' implied. having learnt this simple regex syntax you
>> can avoid the need for looking up strsplit and paste in tfm, so i'd
>> consider it worthwhile.
>>
>
> As people say, YMMV, I do not need to look up strsplit and/or paste;
> but I would have to look up what the regular expression syntax or
> finally memorise it; something I did not consider worthwhile so far.
>
well, the regex syntax is fairly standard, though variations exist among
languages. once you learn it, or rather the ideas behind the syntax,
you're well equipped for quite a range of tasks. on the other hand, the
details of strsplit and paste are pretty r-specific, and you don't gain
much by remembering them (except for freeing yourself from having to
read tfm again).
i have seen quite a bunch of programs written by scientists who spent
over one hundred lines of code on just parsing command line arguments;
i wish they knew regexes exist (and better, getopt-like modules too).
if you're doing serious programming without knowing regexes, you're
rather lucky.
vQ
More information about the R-help
mailing list