Re: [R] How to convert "c:\a\b" to "c:/a/b"?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 28 Jun 2005 - 12:25:36 EST

Try using file.choose() to locate the file instead of Windows Explorer. That will return the name in a form useable within R.

On 6/27/05, Spencer Graves <spencer.graves@pdf.com> wrote:
> Thanks, Dirk, Gabor, Eric:
>
> You all provided appropriate solutions for the stated problem.
> Sadly, I oversimplified the problem I was trying to solve: I copy a
> character string giving a DOS path from MS Windows Explorer into an R
> script file, and I get something like the following:
>
> D:\spencerg\statmtds\R\Rnews
>
> I want to be able to use this in R with its non-R meaning, e.g., in
> readLine, count.fields, read.table, etc., after appending a file name.
> Your three solutions all work for my oversimplified toy example but are
> inadequate for the problem I really want to solve.
>
> Thanks,
> spencer graves
>
> Gabor Grothendieck wrote:
>
> > On 6/27/05, Dirk Eddelbuettel <edd@debian.org> wrote:
> >
> >>On 26 June 2005 at 20:30, Spencer Graves wrote:
> >>| How can one convert back slashes to forward slashes, e.g, changing
> >>| "c:\a\b" to "c:/a/b"? I tried the following:
> >>|
> >>| > gsub("\\\\", "/", "c:\a\b")
> >>| [1] "c:\a\b"
> >>
> >>This does work, provided you remember that single backslashed "don't exist"
> >>as e.g. \a is a character in itself. So use doubles are you should be fine:
> >>
> >>
> >>>gsub("\\\\", "/", "c:\\a\\b")
> >>
> >>[1] "c:/a/b"
> >>
> >
> >
> > Also, if one finds four backslashes confusing one can avoid the use
> > of four via any of these:
> >
> > gsub("[\\]", "/", "c:\\a\\b")
> > gsub("\\", "/", "c:\\a\\b", fixed = TRUE)
> > chartr("\\", "/", "c:\\a\\b")
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> --
> Spencer Graves, PhD
> Senior Development Engineer
> PDF Solutions, Inc.
> 333 West San Carlos Street Suite 700
> San Jose, CA 95110, USA
>
> spencer.graves@pdf.com
> www.pdf.com <http://www.pdf.com>
> Tel: 408-938-4420
> Fax: 408-280-7915
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 28 12:32:31 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:03 EST