Installing R Packages From Source

I upgraded to R version 3.2.2 several months ago and have pretty much reloaded all my packages.

But today I tried running a script that uses the caret package’s implementation of glm() for a logistic regression model. There was a problem … caret wasn’t installed. And when I ran install.packages("caret") I got this message:

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called ‘pbkrtest’

I knew this was a dependency issue, and it was likely I’m not the only person who has run into it. And sure enough:

http://stackoverflow.com/questions/34236629/unable-to-install-packagescaret-completely-in-r-version-3-2-3

OK. So how do I install a package “manually” (i.e. from source)?

I’ve had to do deal with this several times before, and have even had a consult devoted to this issue. But the answer is pretty simple:

http://stackoverflow.com/questions/1474081/how-do-i-install-an-r-package-from-source

As the upvoted response above indicates, the install.packages() function takes several arguments, including “repos” and “type”.

To install a package from source, go to the CRAN page of interest (in my case it’s https://cran.r-project.org/web/packages/pbkrtest/index.html) and download the “Package source”, which should have a “tar.gz” extension. Then in your R console you can use the following:

install.packages(path_to_file, repos = NULL, type="source")

The path_to_file referred to above will depend on where you’ve downloaded the source, and whether or not you’re using a Windows or Unix/Mac operating system.

Related