2

I'm trying to debug why I'm suddenly getting the error

tar.exe: Error exit delayed from previous errors.

on running install_github. Thinking there might be a problem with the tar program, I came across this oddity:

> Sys.getenv("PATH")
[1] "C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\Rtools\\bin;C:\\Windows\\system32;[...]"

> Sys.which("tar")
                             tar 
"C:\\WINDOWS\\SYSTEM32\\tar.exe" 

> file.exists("C:\\Rtools\\bin\\tar.exe")
[1] TRUE

Why is R using the system tar, as opposed to the Rtools-supplied tar, when the Rtools directory is earlier in the path?

OS is Windows 10 2004 (build 19041.330), R 4.0.0.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187

1 Answers1

2

This appears to be a known problem, for... several years now:

How to find correct executable with Sys.which on Windows

I tried to find documentation for this. I came across this:

https://cran.r-project.org/manuals.html

and in turn this:

https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf

but it turns out that PDF is specific to Unix, and omits Windows specific parts. I am not sure of any official Windows PDF. So failing that, you can look at the source directly:

The search path for command may be system-dependent: it will include the bin directory, the working directory and the Windows system directories before PATH.

https://github.com/wch/r-source/blob/92712b53/src/library/base/man/system.Rd#L77-L79

Note on the same page, I also see this:

This interface has become rather complicated over the years: see system2 for a more portable and flexible interface which is recommended for new code.

(If the Windows PDF is hosted in an official place, someone please let me know).

Zombo
  • 1
  • 62
  • 391
  • 407
  • Ta. Looks like `Sys.which` (and `system`) behave like this because it's what the `SearchPath` Win32 function does: http://winapi.freetechsecrets.com/win32/WIN32SearchPath.htm – Hong Ooi Jun 22 '20 at 02:06