How does R handle common dependencies? - r

How does R handle dependencies when 2 or more packages have a common dependency, when using install.packages() to install from CRAN?
I understand the general default is to assume that the most recent version of a package on CRAN works with the other most recent packages on CRAN.
But what happens if:
I install package_1 from CRAN, which depends on dependency_1 v 1.0, so I have both these on my system.
Sometime later I try to install package_2, which also depends on dependency_1 version >=2.0, which is now available on CRAN.
I assume doing this would try to update dependency_1 to v 2.0
At this point my installed version of package_1 is now out of date with CRAN, where package_1 now has dependency_1 version >=2.0 also.
Unfortunately, this means my installed version of package_1 is relying on certain behaviour from dependency_1 which isn't present in v2.0, and so consequently won't work any more
At this point, will R:
Check package_1 is up to date, and update it accordingly along with dependency_1, when installing package_2?
Identify the potential conflict, and fail to install package_2?
Install package_2, update dependency_1, and leave me to find the conflict between my version of package_1 and dependency_1?
Do something else I haven't thought of?!

Related

Arte there any free alternatives to packages "translate" and "translateR"? [duplicate]

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?
To install an older version of a package from source (within R):
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
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:
# install yesterday's version of checkpoint, by date
install.dates('checkpoint', Sys.Date() - 1)
# install earlier versions of checkpoint and devtools
install.versions(c('checkpoint', 'devtools'), c('0.3.3', '1.6.1'))
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 using wget (if you have it):
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
or, if you're on Windows, an equivalent using PowerShell would be:
(new-object System.Net.WebClient).DownloadFile("http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz", "./ggplot2_0.9.1.tar.gz")
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:
R CMD INSTALL ggplot2_0.9.1.tar.gz
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.
The remotes package offers an install_version function that can do this directly.
require(remotes)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
Previously, this answer pointed to the devtools package, which also re-exports the install_version function. Thanks #MichaelChirico for pointing out that the remotes package is preferable.
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
Pure install.packages method
See this thread on the r-devel mailing list. In reply to Kurt Wheeler, Kurt Hornik reveals an undocumented feature of the CRAN website to specify the specific version of a package.
This method will work as long as you have all required dependencies already installed:
package = "https://cran.r-project.org/package=svglite&version=1.2.1"
utils::install.packages(pkgs = package, repos = NULL)
Note the URL structure above. This addresses the issue that CRAN has a different URL structure for the latest version than for archived versions:
# Latest version (not available at Archive/svglite)
https://cran.r-project.org/src/contrib/svglite_1.2.1.tar.gz
# Archived version
https://cran.r-project.org/src/contrib/Archive/svglite/svglite_1.2.0.tar.gz
remotes::install_version method
Another option is to use the remotes::install_version function. However, you will need to install the remotes package.
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 package devtools.
Another possibility that I have not explored further:
Download the older .tar.gz source file from the package archives.
Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
There is a versions package that simplifies this task considerably, for package versions released since 2014-09-17. It uses snapshots of the MRAN server at Revolution Analytics to:
show release dates and MRAN availability of any CRAN package (available.versions),
install specified versions of one or more packages(install.versions), or
install package versions available as of any specified date (install.dates). It does the installation from the MRAN server via the standard install.packages function, so available binary versions can be installed instead of having to compile from source, and package dependencies as of the specified date can be included.
There might of course be compatibility issues with combinations of package versions and R versions. For running different R versions, see for example this page.
Found a good solution, which worked for me (the details are at the link).
Command in "repmis" library:
# Install old versions of the e1071 and gtools packages.
# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")
# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)
Another option is the {groundhog} package. It helps install an older package Version from CRAN by specifying a date. This is especially helpful when one doesn't remember the specific package version, but rather the time the script was still working. In case of {ggplot2} version 0.9.1 was loaded on CRAN in May 2012 so we can take a date from June.
library("groundhog")
groundhog.library("ggplot2", "2012-06-01")

Saving an R session [duplicate]

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?
To install an older version of a package from source (within R):
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
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:
# install yesterday's version of checkpoint, by date
install.dates('checkpoint', Sys.Date() - 1)
# install earlier versions of checkpoint and devtools
install.versions(c('checkpoint', 'devtools'), c('0.3.3', '1.6.1'))
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 using wget (if you have it):
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
or, if you're on Windows, an equivalent using PowerShell would be:
(new-object System.Net.WebClient).DownloadFile("http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz", "./ggplot2_0.9.1.tar.gz")
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:
R CMD INSTALL ggplot2_0.9.1.tar.gz
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.
The remotes package offers an install_version function that can do this directly.
require(remotes)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
Previously, this answer pointed to the devtools package, which also re-exports the install_version function. Thanks #MichaelChirico for pointing out that the remotes package is preferable.
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
Pure install.packages method
See this thread on the r-devel mailing list. In reply to Kurt Wheeler, Kurt Hornik reveals an undocumented feature of the CRAN website to specify the specific version of a package.
This method will work as long as you have all required dependencies already installed:
package = "https://cran.r-project.org/package=svglite&version=1.2.1"
utils::install.packages(pkgs = package, repos = NULL)
Note the URL structure above. This addresses the issue that CRAN has a different URL structure for the latest version than for archived versions:
# Latest version (not available at Archive/svglite)
https://cran.r-project.org/src/contrib/svglite_1.2.1.tar.gz
# Archived version
https://cran.r-project.org/src/contrib/Archive/svglite/svglite_1.2.0.tar.gz
remotes::install_version method
Another option is to use the remotes::install_version function. However, you will need to install the remotes package.
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 package devtools.
Another possibility that I have not explored further:
Download the older .tar.gz source file from the package archives.
Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
There is a versions package that simplifies this task considerably, for package versions released since 2014-09-17. It uses snapshots of the MRAN server at Revolution Analytics to:
show release dates and MRAN availability of any CRAN package (available.versions),
install specified versions of one or more packages(install.versions), or
install package versions available as of any specified date (install.dates). It does the installation from the MRAN server via the standard install.packages function, so available binary versions can be installed instead of having to compile from source, and package dependencies as of the specified date can be included.
There might of course be compatibility issues with combinations of package versions and R versions. For running different R versions, see for example this page.
Found a good solution, which worked for me (the details are at the link).
Command in "repmis" library:
# Install old versions of the e1071 and gtools packages.
# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")
# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)
Another option is the {groundhog} package. It helps install an older package Version from CRAN by specifying a date. This is especially helpful when one doesn't remember the specific package version, but rather the time the script was still working. In case of {ggplot2} version 0.9.1 was loaded on CRAN in May 2012 so we can take a date from June.
library("groundhog")
groundhog.library("ggplot2", "2012-06-01")

Install previous version of libraries in R [duplicate]

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?
To install an older version of a package from source (within R):
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
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:
# install yesterday's version of checkpoint, by date
install.dates('checkpoint', Sys.Date() - 1)
# install earlier versions of checkpoint and devtools
install.versions(c('checkpoint', 'devtools'), c('0.3.3', '1.6.1'))
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 using wget (if you have it):
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
or, if you're on Windows, an equivalent using PowerShell would be:
(new-object System.Net.WebClient).DownloadFile("http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz", "./ggplot2_0.9.1.tar.gz")
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:
R CMD INSTALL ggplot2_0.9.1.tar.gz
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.
The remotes package offers an install_version function that can do this directly.
require(remotes)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
Previously, this answer pointed to the devtools package, which also re-exports the install_version function. Thanks #MichaelChirico for pointing out that the remotes package is preferable.
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
Pure install.packages method
See this thread on the r-devel mailing list. In reply to Kurt Wheeler, Kurt Hornik reveals an undocumented feature of the CRAN website to specify the specific version of a package.
This method will work as long as you have all required dependencies already installed:
package = "https://cran.r-project.org/package=svglite&version=1.2.1"
utils::install.packages(pkgs = package, repos = NULL)
Note the URL structure above. This addresses the issue that CRAN has a different URL structure for the latest version than for archived versions:
# Latest version (not available at Archive/svglite)
https://cran.r-project.org/src/contrib/svglite_1.2.1.tar.gz
# Archived version
https://cran.r-project.org/src/contrib/Archive/svglite/svglite_1.2.0.tar.gz
remotes::install_version method
Another option is to use the remotes::install_version function. However, you will need to install the remotes package.
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 package devtools.
Another possibility that I have not explored further:
Download the older .tar.gz source file from the package archives.
Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
There is a versions package that simplifies this task considerably, for package versions released since 2014-09-17. It uses snapshots of the MRAN server at Revolution Analytics to:
show release dates and MRAN availability of any CRAN package (available.versions),
install specified versions of one or more packages(install.versions), or
install package versions available as of any specified date (install.dates). It does the installation from the MRAN server via the standard install.packages function, so available binary versions can be installed instead of having to compile from source, and package dependencies as of the specified date can be included.
There might of course be compatibility issues with combinations of package versions and R versions. For running different R versions, see for example this page.
Found a good solution, which worked for me (the details are at the link).
Command in "repmis" library:
# Install old versions of the e1071 and gtools packages.
# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")
# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)
Another option is the {groundhog} package. It helps install an older package Version from CRAN by specifying a date. This is especially helpful when one doesn't remember the specific package version, but rather the time the script was still working. In case of {ggplot2} version 0.9.1 was loaded on CRAN in May 2012 so we can take a date from June.
library("groundhog")
groundhog.library("ggplot2", "2012-06-01")

Use a package's older version in R [duplicate]

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?
To install an older version of a package from source (within R):
packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
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:
# install yesterday's version of checkpoint, by date
install.dates('checkpoint', Sys.Date() - 1)
# install earlier versions of checkpoint and devtools
install.versions(c('checkpoint', 'devtools'), c('0.3.3', '1.6.1'))
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 using wget (if you have it):
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
or, if you're on Windows, an equivalent using PowerShell would be:
(new-object System.Net.WebClient).DownloadFile("http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz", "./ggplot2_0.9.1.tar.gz")
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:
R CMD INSTALL ggplot2_0.9.1.tar.gz
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.
The remotes package offers an install_version function that can do this directly.
require(remotes)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
Previously, this answer pointed to the devtools package, which also re-exports the install_version function. Thanks #MichaelChirico for pointing out that the remotes package is preferable.
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
Pure install.packages method
See this thread on the r-devel mailing list. In reply to Kurt Wheeler, Kurt Hornik reveals an undocumented feature of the CRAN website to specify the specific version of a package.
This method will work as long as you have all required dependencies already installed:
package = "https://cran.r-project.org/package=svglite&version=1.2.1"
utils::install.packages(pkgs = package, repos = NULL)
Note the URL structure above. This addresses the issue that CRAN has a different URL structure for the latest version than for archived versions:
# Latest version (not available at Archive/svglite)
https://cran.r-project.org/src/contrib/svglite_1.2.1.tar.gz
# Archived version
https://cran.r-project.org/src/contrib/Archive/svglite/svglite_1.2.0.tar.gz
remotes::install_version method
Another option is to use the remotes::install_version function. However, you will need to install the remotes package.
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 package devtools.
Another possibility that I have not explored further:
Download the older .tar.gz source file from the package archives.
Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
There is a versions package that simplifies this task considerably, for package versions released since 2014-09-17. It uses snapshots of the MRAN server at Revolution Analytics to:
show release dates and MRAN availability of any CRAN package (available.versions),
install specified versions of one or more packages(install.versions), or
install package versions available as of any specified date (install.dates). It does the installation from the MRAN server via the standard install.packages function, so available binary versions can be installed instead of having to compile from source, and package dependencies as of the specified date can be included.
There might of course be compatibility issues with combinations of package versions and R versions. For running different R versions, see for example this page.
Found a good solution, which worked for me (the details are at the link).
Command in "repmis" library:
# Install old versions of the e1071 and gtools packages.
# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")
# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)
Another option is the {groundhog} package. It helps install an older package Version from CRAN by specifying a date. This is especially helpful when one doesn't remember the specific package version, but rather the time the script was still working. In case of {ggplot2} version 0.9.1 was loaded on CRAN in May 2012 so we can take a date from June.
library("groundhog")
groundhog.library("ggplot2", "2012-06-01")

Update a package and keep it from reverting to the original

I want to upgrade the package ggplot2:
library(ggplot2)
packageDescription("ggplot2")["Version"]
> 0.8.3
But the current version is 0.8.7.
I tried update.packages(), which seemed to work OK. But it still returned older version 0.8.3.
So I downloaded and installed the package source from Cran, which says 0.8.7 in the download page.
I then install it via the GUI menu in R. It returns
** building package indices ...
* DONE (ggplot2)
I then run:
packageDescription("ggplot2")["Version"]
> 0.8.3
And still I have the older version!
I don't know why this is not working, what's more I had already come across this problem before and solved it (I can't remember exactly what) but now it has gone back to the older version! What's the easiest way to keep packages like this updated automatically and not have them refer back to older packages?
What version of R are you using? CRAN binaries are only kept up-to-date for the latest R release (i.e. 2.10.1). If you have an older version of R and have the development tools installed, you can use install.packages("ggplot2",type="source").
Did you do unloadNamespace('ggplot2')? and the library(ggplot2) and then check the version? Because, once you load a package, it stays in memory of R, even though you might have already installed a newer version of the package, R does not see, until you do the above.

Resources