Bug 16660 - Discordance between doc and behavior for R.home() on windows
Summary: Discordance between doc and behavior for R.home() on windows
Alias: None
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific (show other bugs)
Version: R 3.2.3
Hardware: All Windows 64-bit
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2016-01-08 14:07 UTC by Tensibai
Modified: 2016-01-11 11:20 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Tensibai 2016-01-08 14:07:24 UTC
According to the doc:

"On Windows the values of R.home() and R_HOME are guaranteed not to contain spaces, switching to the 8.3 short form of path elements if required."

That said on my windows 7 (and as far as I can guess, 2008R2 and older versions too):

> R.home()
[1] "C:/Program Files/R/R-3.2.3"

After a few research this is because the GetShortPathName function use in getRHOME[1] on windows rely on the 8dot3name aliasing to be enable, when it's not it return a long path.
Source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

I assume the value should be queried and spaces properly escaped if the value is disabled, or the doc has to be updated accordingly.

Tested on R 3.2.2 and 3.2.3, I assume the behavior is the same for all versions as it's independent from R.

My current workaround is to install R in a path with no space to fix this.

[1] Here on github: https://github.com/wch/r-source/blob/b156e3a711967f58131e23c1b1dc1ea90e2f0c43/src/gnuwin32/rhome.c#L69
Comment 1 Tensibai 2016-01-08 14:15:49 UTC
Oops forgot a point: This broke `build` calls with a '"C:\Program" is not a file or directory' error.
Comment 2 Duncan Murdoch 2016-01-10 10:11:00 UTC
If the service to provide an 8.3 name is disabled, then clearly that "guarantee" can't be honored.  I'll fix the docs.

The problem of spaces in filenames is hard to fix in Windows, as there is no standard way to quote arguments to functions.  (See the discussion in bug 16636).  However, we can probably fix an instance of it.  Could you post details of how to reproduce this, including how to disable 8.3 names?
Comment 3 Tensibai 2016-01-11 09:23:18 UTC
I agree spaces in paths is a pain, whichever the OS is, and windows taste of having a 'program files' directory is really annoying :)

For the 8dot3names, starting with win7, they are disabled by default (unless the path exceed 260 chars and then they are activated by default.

The way to disable it is to use [fsutils][1] like this

fsutil 8dot3name set 1

and then strip the 8dot3names by 

fsutil 8dot3name strip c:

This has implication if short names are registered in registry, so better to be done on a dropable box if possible.

I found this while trying to install a package with the devtools library, which get the path to R.exe by a call to R.home("bin"), I assume the fix has to be done there more than core R.

At the end of the day, I think an update to the doc to include a warning as in shortPathName documentation is enough.

Comment 4 Brian Ripley 2016-01-11 10:41:42 UTC
It seems you missed

'If you want to be able to build packages from sources, we recommend that you choose an installation path not containing spaces.'

(the rw-FAQ).

That guarantee was from MicroSoft at the time that help page was written (well before Windows 7).
Comment 5 Tensibai 2016-01-11 11:20:06 UTC

I just think it worth updating the doc, and maybe changing the default install path for R core to avoid those kind of problems.

That's just a proposition, as long as the doc state it, I think it is enough to close this ticket.

Opening the talk was to have a little more feedback if I did miss a point and there's was an easy solution to fix it, seems there's no easy solution, so just a doc fix is ok IMHO.