Windows - Validating local repository, not as easy as it sounds
Hi.
I am trying to use drat to expose private packages into our organization internal GitHub.
I am working on Windows and I had a "nice time" trying to validate the repository created locally but finally I managed.
I am raising this for your own amusement and also as this could be nice to maybe document so that the next guy don't waste hours like I did while trying to test the local repository ^_^
On Drat git repo session
drat::insertPackage("c:/fullpath/using/forward/slashes/package.tar.gz",
repodir = getOption("dratRepo", "c:/forward/slashed/path/git/docs"))
# source package added as expected, in src\contrib and index created
drat::insertPackage("c:/fullpath/using/forward/slashes/package.zip",
repodir = getOption("dratRepo", "c:/forward/slashed/path/git/docs"))
# binary package added as expected, in bin\windows\contrib\4.2 and index created
Using separate R session,
Using forward slashes path with verbose flag set [FAILURE]
# using forward slashes path
install.packages("mypackage", repos = "c:/Users/myuser/source/work/r/drat-repo/git/docs", verbose = TRUE)
# fails with output
Installing package into ‘C:/Users/myuser/source/work/r/fresh/renv/library/R-4.2/x86_64-w64-mingw32’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository c:/Users/myuser/source/work/r/drat-repo/git/docs/src/contrib:
cannot open URL 'c:/Users/myuser/source/work/r/drat-repo/git/docs/src/contrib/PACKAGES'
Warning: unable to access index for repository c:/Users/myuser/source/work/r/drat-repo/git/docs/bin/windows/contrib/4.2:
cannot open URL 'c:/Users/myuser/source/work/r/drat-repo/git/docs/bin/windows/contrib/4.2/PACKAGES'
Warning message:
package ‘mypackage’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Then using backward slashes path and verbose flag set [FAILURE]
# using forward slashes path
install.packages("mypackage", repos = "c:\\Users\\myuser\\source\\work\\r\\drat-repo\\git\\docs", verbose = TRUE)
# fails with output
Installing package into ‘C:/Users/myuser/source/work/r/fresh/renv/library/R-4.2/x86_64-w64-mingw32’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository c:\Users\myuser\source\work\r\drat-repo\git\docs/src/contrib:
cannot open URL 'c:\Users\myuser\source\work\r\drat-repo\git\docs/src/contrib/PACKAGES'
Warning: unable to access index for repository c:\Users\myuser\source\work\r\drat-repo\git\docs/bin/windows/contrib/4.2:
cannot open URL 'c:\Users\myuser\source\work\r\drat-repo\git\docs/bin/windows/contrib/4.2/PACKAGES'
Warning message:
package ‘mypackage’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
More or less same output but we can see that output warnings contains path with backward slashes
Then, using backward slashes path and the file: prefix, still with verbose flag set [SUCCESS but without dependencies]
# using forward slashes path
install.packages("mypackage", repos = "file:c:\\Users\\myuser\\source\\work\\r\\drat-repo\\git\\docs", verbose = TRUE)
# succeeds
Installing package into ‘C:/Users/myuser/source/work/r/fresh/renv/library/R-4.2/x86_64-w64-mingw32’
(as ‘lib’ is unspecified)
Warning: dependencies (...) are not available
package ‘mypackage’ successfully unpacked and MD5 sums checked
Then cherry on the cake, using any of the 3 previous path formats and verbose flag not set like
install.packages("mypackage", repos = "c:/Users/myuser/source/work/r/drat-repo/git/docs")
install.packages("mypackage", repos = "c:\\Users\\myuser\\source\\work\\r\\drat-repo\\git\\docs")
install.packages("mypackage", repos = "file:c:\\Users\\myuser\\source\\work\\r\\drat-repo\\git\\docs")
All goes well, including install of dependencies [PARTY TIME]
In case this would interest you as well, while trying to use pak with any of the paths it fails :(
pak::repo_add(localRepo = "c:/Users/myuser/source/work/r/drat-repo/git/docs")
pak::pkg_install("mypackage")
# fails
Error:
! error in pak subprocess
Caused by error:
! Could not solve package dependencies:
* mypackage: Can't find package called mypackage.
Thanks already for reading this quite long post ^_^
Interesting. I think when you want a file path you actually must prefix it with file:// as you did (and I am unsure about the slashes). This comes from R, and possibly the Windows C library. We can possibly experiment a little more, and I think this is mostly a documentation issue. Thanks for posting!
No worries, thanks for your prompt feedback.
That's most likely not a drat issue per say, but I thought it could be interesting for you to know, play with and document.
I was quite disappointed by this VERBOSE flag side effect and almost as much by pak which is usually quite handy.
Please close this ticket when you think it is right.
I have another issue related to GitHub permissions that I am not able to figure out, so I'll create another ticket to keep both asides :)