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, 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) >> paste(x[1:(length(x)-1)], collapse=".")) >> [1] "myoutput" >> R> myfile2 <- c(myfile, "path2/path3/myoutput.temp") >> R> sapply(strsplit(basename(myfile2),"\\."), function(x) >> paste(x[1:(length(x)-1)], collapse=".")) >> [1] "myoutput" "myoutput" >> R> myfile3 <- c(myfile2, "path4/path5/my.out.put.xls") >> R> sapply(strsplit(basename(myfile3),"\\."), function(x) >> paste(x[1:(length(x)-1)], collapse=".")) >> [1] "myoutput" "myoutput" "my.out.put" >> >> > > 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. ______________________________________________ R-help@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.