[R] Extracting File Basename without Extension

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jan 9 16:00:52 CET 2009


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 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".

Windows (where file extensions really mean something), though reluctant 
to create such a file, appears to agree that the extension is bashrc, 
even though to me it appears clear that that file has no extension.

Duncan Murdoch




More information about the R-help mailing list