Re: how to put a single backslash into a string, to make file paths usable on windows
Spencer Graves <[email protected]> Thu, 7 May 2026 21:53:49 -0500
| Newsgroups | gmane.comp.lang.r.general |
|---|---|
| Message-ID | <[email protected]> |
See also:
file.path(..., fsep = .Platform$file.sep)
https://web.mit.edu/~r/current/lib/R/library/base/html/file.path.html
I'm not sure, but help(".Platform") seems to support what I get from
Richard O'Keefe, that "you can safely use / in file name" perhaps no
matter which platform. At one point that was not true, but it may be the
case now. Sorry: I cannot easily check. Spencer Graves
On 5/7/26 21:30, Richard O'Keefe wrote:
> This isn't an R thing. The Windows system calls that accept file names
> accept both kinds of slash indifferently. I've seen it said that this goes
> back to MS-DOS 2, but certainly it's all NT versions. If you need to link
> C and/or Fortran with R, you can safely use / in file name strings in those
> languages too.
>
> On Fri, 8 May 2026 at 01:18, Chris Ryan <[email protected]> wrote:
>
>> It had been about a year since I had worked in Windows, and apparently I
>> had gotten rusty. Forward slashes in path names, as in
>>
>> read.csv("e:/path/to/datafileOnWindows.csv")
>>
>> work just fine in R on Windows.
>>
>> Sorry for the bother.
>>
>> --Chris Ryan
>>
>>
>>
>> Chris Ryan wrote:
>>> I'm trying to generalize one of my scripts so that it will run on my
>>> Linux Mint computer at home and my client's Windows 11 computer at work.
>>> I'm encountering trouble when setting file paths, conditional on which
>>> computer the script is running on. It's the Windows backslash issue
>>>
>>
>> ______________________________________________
>> [email protected] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> https://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.