Re: [Rd] Questions on "\" vs "/" on Windows

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 20 Aug 2005 - 14:13:35 GMT

On 8/20/05, Seth Falcon <sfalcon@fhcrc.org> wrote:
> A recent thread on R-help reminded me of some questions I have
> regarding the path separator on Windows.
>
> The thread: [R] using paste and "\" to create a valid filename
>
> The question:
>
> What are the use-cases where "\" is required for paths passed as
> character vectors from within R?

I think Windows itself allows / but some programs require \.

>
> My experience has been that "/" always works and "\" often fails due
> to escaping issues (the user's fault). A pathalogical example
> that I _have_ encountered due to temp file naming on Windows:
>
> > badpath <- "foo\\2\\bar"
> > root <- "c:\\HERE\\file.txt"
> > gsub("HERE", badpath, root)
> Error in gsub("HERE", badpath, root) : invalid backreference 2 in regular expression
>
> Using file.path is recommended as a best practice, but AFAICT, it
> forces "\" on Windows.

Actually it uses /. On my Windows XP system:

> file.path("a", "b")

[1] "a/b"
> R.version.string

[1] "R version 2.1.1, 2005-06-23"  

>
> Why not have file.path dynamically read .Platform$file.sep
> so that in code that uses file.path one could modify
> .Platform$file.sep and change the behavior of all subsequent file.path
> calls?
>
> Python's os.path.join function behaves similarly to R's: changing
> os.sep doesn't change the behavior of os.path.join.
> .Platform$file.sep = "/" and change the behavior of all subsequent
> calls.
>
> With both languages, I've found that for glue-code type tasks,
> sticking to "/" on Windows is much easier and I've been frustrated by
> the built-in path handling function.

>
> + seth



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun Aug 21 00:18:08 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:27:40 GMT