On Windows, dir.create() with recursive=TRUE attempts to create each directory in the path, even if it already exists. This is problematic when the user has restricted write access, for instance, on a network share. For example:
> dir.create('\\\\sharename\\Empl\\Home1\\active\\e\\ecortens\\thisisatest', recursive = TRUE)
In dir.create("\\\\sharename\\Empl\\Home1\\active\\e\\ecortens\\thisisatest", :
cannot create dir '\\ad.mtroyal.ca\Empl', reason 'Permission denied'
I have write access within "ecortens", but, naturally, not within the root of the network share, so it's erroring because it's trying to create "Empl" in a directory that I can't write to.
This is problematic, for instance, in the creation of the 00LOCK directory in install.packages(), which is a call to dir.create() with recursive=TRUE.
I'm not comfortable enough with my C abilities to submit a patch, but the fix, I think, is around line 2170 of src/main.c (in the latest R-devel, checked out from subversion). I know that errno of EEXIST isn't supposed to trigger an exit, but for whatever reason, the Windows API is not setting errno to EEXIST, even though the directory does exist.
The solution, I think, would be to call _wstat() and check that the directory exists, and is a directory, and if so, move to the next chunk of the path, rather than trying to _wmkdir().
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
 LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
 LC_TIME=English_United States.1252
attached base packages:
 stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
 tools_3.3.1 withr_1.0.2 memoise_1.0.0 digest_0.6.10 devtools_1.12.0
Created attachment 2167 [details]
A patch that will skip both the server and the share
I'm not sure if this is the correct behaviour for all versions of windows. It solves the problem for me, however.