[R] Extracting File Basename without Extension
William Dunlap
wdunlap at tibco.com
Wed Jan 14 18:46:07 CET 2009
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 include any
initial dot. Unlike the Unix basename, the suffix is a regular
expression (but other regexpr arguments like ignore.case and
fixed are not acceptedi - there ought to be a regular expression
class so these things get attached to the expression instead of
added to the call).
> basename(c("foobar", "dir/foo.bar"), suffix=".bar")
[1] "fo" "foo"
> basename(c("foobar", "dir/foo.bar"), suffix="\\.bar")
[1] "foobar" "foo"
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
More information about the R-help
mailing list