[R] Errors in R package installation

Ivan Krylov
Fri, 13 Dec 2019 14:12:56 -0000

On Fri, 13 Dec 2019 13:19:54 +0000
David Stevens <david.stevens at usu.edu> wrote:

>   There are binary versions available but the source versions are
>   later:

Okay, that would be the reason why would R on Windows try to install a
source package instead of a binary package. One can also see that callr
has just been successfully installed from a binary package (that took
time to be built from a freshly updated source package and was
unavailable yesterday) -- but now there are other updated packages that
cannot be installed.

On Fri, 13 Dec 2019 13:14:28 +0000
David Stevens <david.stevens at usu.edu> wrote:

> I read a thread elsewhere that said a work around is to run
> options(pkgType='binary') before installation and the problem went
> away. Does this help.

Yes, this again points us at the differences between installing source
packages and "win.binary" packages.

> Yes, this is the case. I do the regular Windows 10 updates and update
> R and RStudio as soon as I am aware there's a new version out. I
> haven't explicitly change %USERPROFILE%.

Since new packages are published all the time, it is likely that your R
installation was able to install source packages successfully, until
recently.

> tempdir() gives
>
> tempdir()
> [1] "C:\\Users\\David Stevens\\AppData\\Local\\Temp\\RtmpQpqh0t"

Yes, this is a problem.

file.path(tempdir(), "downloaded_packages") is passed to
download.packages() and used to store the downloaded files. Eventually,
download.packages() returns destination file paths (which now contain
spaces), which are then passed to what amounts to:

system2(
 command = file.path(R.home("bin"), "R"),
 args = c("CMD", "INSTALL", path), ...
)

system2() uses paste(c(env, shQuote(command), args), collapse = " ")
to
form a command line and eventually passes that command line to
CreateProcess(). The path value is left unquoted, causing the error
observed above.

I believe that this is a bug in install.packages() and that the
`fil` argument in [*] should be quoted using shQuote() just like it is
quoted in all other invocations of R CMD INSTALL in the same file.

A workaround that should have worked but didn't was to pass a writeable
path without spaces as a destdir = ... argument to install.packages().
I am not sure why did install.packages() decide to use C:/myRLib as the
library instead of a temp directory to download files in (we just need
a temp directory, not a separate library). Try the following again in a
clean session?

install.packages(
 c('lmerTest', 'quantreg', 'rmarkdown',
'SparseM'),
 lib = .libPaths()[1L],
 destdir = 'c:/myRLib'
)

--
Best regards,
Ivan

[*]