I am trying to use Rpy2 and ggplot2 but I get an error. After some searching for the error online, I found that the error occurs because there are changes in the ggplot2 package that are not yet reflected in Rpy2 (for example, see this post (Edit: Link is now dead)).
So I now need to install an older version of ggplot2. Here is pseudo-code for what I want:
install.packages("ggplot2", version='0.9.1')
But install.packages
does not have a version
argument. How do I do it?
The
devtools
package offers aninstall_version
function that can do this directly.Found a good solution, which worked for me (the details are at the link).
Command in "repmis" library:
You can download your appropriate version from the link below as a zip file.
http://cran.r-project.org/src/contrib/Archive/ggplot2/
In R Studio: Tools >> Install packages >> Install from: (select drop down)
Package Archive File(.zip, .tar.gz).
Choose your newly-downloaded-package-zip-file and install the package
To install an older version of a package from source (within R):
If this doesn't work for you and you're on Windows, the reason is probably the lack of an appropriate tool chain for building/compiling packages. Normally you would install a pre-compiled binary from CRAN but they only archive package sources, not binaries.[1] This means you need to install Rtools so that you can compile everything locally. (Note: Rtools is not an R package.)
@shadow's answer below also makes the case that you can use
devtools::install_version()
. That's also a good idea, but is also subject to needing Rtools on Windows.As of September 18, 2015, a new package versions has appeared on CRAN. This relies on the Revolution Analytics MRAN server to install packages for specific versions or dates:
That has the advantage of not requiring Rtools to install binary packages on Windows, but only works going back to 2014-09-17 (when MRAN was launched).
To install an older version from the command line (outside of R):
You can also install a package by using
R CMD INSTALL
on the command line (Terminal, Command Prompt, etc.) once you have the package source ("tarball") locally on your machine, for example usingwget
(if you have it):or, if you're on Windows, an equivalent using PowerShell would be:
or you can just download the source from the CRAN archive via your web browser.
To install from the local file, you can just do:
That should work on any platform (with the same caveat - as above - about needing a tool chain for building packages).
[1]This is no longer entirely true. From March 2016, CRAN has started hosting a "CRAN Archive" server that contains Windows and Mac binaries for very old versions of R (> 5 years old). You can now install directly from this server using
install.packages()
. See new R FAQ 7.44 for some details.Using
install.packages
as described in another answer does not work for me.The best alternative I found is to use function
install_url
from packagedevtools
.Another possibility that I have not explored further: