[R] Extracting File Basename without Extension

jim holtman jholtman at gmail.com
Fri Jan 9 03:37:55 CET 2009


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 Viswanath <gundalav at gmail.com> 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'
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list