0

I'm not able to install packages from source to R in Windows, and I have not been able to find anybody else with this error here and elsewhere online.

I'm working on a PC that is not my personal PC, and I'm able to install packages to only two different directories. The file path of each of these drives start with two forward slashes ("//"), and only work with these forwards slashes or work if the forward slashes are replaced by backward slashes ("\\").

If I try to install to a directory "//drive/filepath" for (for example) H2O:

install.packages("h2o", type="source", repos="http://h2o-release.s3.amazonaws.com/h2o/rel-xu/1/R", lib = "//drive/filepath")

R downloads the .tar.gz source file fine, however when it tries to install it I get the error:

* installing *source* package 'h2o' ...
** R
** demo
** inst
Warning in file.create(to[okay]) :
  cannot create file '\drive/filepath/h2o/branch.txt', reason 'No such file or directory'
(THEN THE SAME WARNING FOR MULTIPLE OTHER FILES IT TRIES TO INSTALL TO THE SAME PATH)
** byte-compile and prepare package for lazy loading
Warning in file(con, "r") :
  cannot open file '\\drive/filepath/h2o/branch.txt': No such file or directory
Error in file(con, "r") : cannot open the connection
Error : unable to load R code in package 'h2o'
ERROR: lazy loading failed for package 'h2o'
* removing '\\drive/filepath/h2o'
In R CMD INSTALL
Warning in install.packages :
  installation of package ‘h2o’ had non-zero exit status

So what it looks like R is doing is converting the double forward slash ("//") at the start of the file path into a double backwards slash ("\"). R then recognises ("\") in the string as the escape character for a single back slash ("\"), so the string where it tries to install the files becomes simply "\drive/filepath", which doesn't work. That's what I think is happening, anyway.

I tried instead to use four forward slashes, thinking it would change this to four backwards slashes, and thus it would look for a drive with two backwards slashes:

install.packages("h2o", type="source", repos="http://h2o-release.s3.amazonaws.com/h2o/rel-xu/1/R", lib = "////drive/filepath")

However it tried to find the file path before converting the forward slashes into backwards slashes, and obviously didn't recognise it as an existing file path:

Warning in install.packages :
  'lib = "////drive/directory"' is not writable
Error in install.packages : unable to install packages

I also tried the command using four and eight backwards slashes, with the same result, ie. the two commands below give the same error as above:

install.packages("h2o", type="source", repos="http://h2o-release.s3.amazonaws.com/h2o/rel-xu/1/R", lib = "\\\\drive/filepath")

install.packages("h2o", type="source", repos="http://h2o-release.s3.amazonaws.com/h2o/rel-xu/1/R", lib = "\\\\\\\\drive/filepath")

Is there any way for me to fix this, please? As I said, I don't own this PC (it belongs to somebody else) so creating/changing drives is not an option, neither is downloading other software.

Note: I can install from .zip files fine.

GMSL
  • 355
  • 2
  • 11
  • 1
    Have you tried referencing the target using a platform agnostic constructor (e.g. `file.path()` or `fs::path()`)? – edavidaja Jan 07 '19 at 14:30
  • I just tried them, thanks. The issue is that those functions just return the string "//drive/filepath" which wasn't working in the first place. I'm getting more and more confident that, for some reason, R is initially checking the file path "//drive/filepath" exists, then downloading the package, then removing the leading "/" (as described by help file for file.path?), and trying to install files to "/drive/filepath", which doesn't exist. Not sure why it's doing that. – GMSL Jan 09 '19 at 08:24
  • R has a pretty difficult time with windows network paths. The third answer [here](https://stackoverflow.com/questions/18570102/how-to-read-files-from-a-unc-specified-directory-in-r) may be of some use to you; otherwise, google around for "R UNC paths" and see what else turns up that might be useful. – edavidaja Jan 09 '19 at 20:10
  • Didn't work, but your comment helped. From that link I now know that these are called "UNC paths". The error message does specifically say "UNC paths are not supported". So the answer is I can't install to the drives I want from source in R, but that's not a glitch it's just a known thing that's not supported. Thanks for the help! – GMSL Jan 10 '19 at 08:02

2 Answers2

0

The answer is that this cannot be done currently (with the version of R that is most recent at time of writing, v3.5.1 "Feather Spray"). Starting a file path with "//" or "\" is UNC-specified directory, which is not supported in the current version of R for installing packages from source.

GMSL
  • 355
  • 2
  • 11
-1

write this path "\\\\drive\\directory"

If it still not able to write then run your script as administrator

Mehul Katara
  • 907
  • 11
  • 32
  • I did say that I tried the "\\\\drive\\directory", however I appreciate that I wrote lots of text and thus it wasn't clear that I tried that, so I've edited the question to make it more clear. Thanks! – GMSL Jan 07 '19 at 14:14