Installing BayesLogit package - r

I am trying to install the BayesLogit package in R. The package was removed from the CRAN website, but I have the source files BayesLogit_0.6.tar.gz. I try running
install.packages("BayesLogit_0.6.tar.gz", type = "source", repos = NULL)
but get the following error: installation of package ‘BayesLogit_0.6.tar.gz’ had non-zero exit status.
Can anyone help, or can you no longer install this package? I have the package installed on another machine, which I installed it back when it was on the CRAN website.

I was able to install the package on my Ubuntu machine with devtools::install_version("BayesLogit", "0.6")
Because the package has C++ source files, you well need compilation tools. If you use Windows, that means you will need to install RTools. On Mac, you will need the Xcode command line tools. See also How do I install a package that has been archived from CRAN? and https://cran.r-project.org/bin/windows/Rtools/

Linux
Run these commands in the R session:
install.packages("devtools") # optional, in case you don't have it
require(devtools)
install_version("BayesLogit", version = "0.6") # the latest version on CRAN archive
macOS
Compiling BayesLogit from source requires GFortran, which requires XCode and command-line tools:
install XCode from the App Store, or install only command-line tools only (e.g., from this thread)
install gfortran, e.g. using an appropriate disk image
run the same code as above inside R:
install.packages("devtools") # optional, in case you don't have it
require(devtools)
install_version("BayesLogit", version = "0.6") # the latest version on CRAN archive
Alternative package
The GitHub page of BayesLogit was last updated 11 months ago, so I venture a guess that it will not be on CRAN. An alternative is this package, which implements the same Polya-Gamma scheme as BayesLogit and has very similar syntax:
# BayesLogit
obj <- BayesLogit::logit(y=y, X=X, P0=diag(rep(precision, ncol(X)), samp=n_samples, burn=burn)
# PolyaGamma
obj <- PolyaGamma::gibbs_sampler(y=y, X=X, lambda=precision, n_iter_total=burn + n_samples, burn_in=burn)
To install the PolyaGamma package, run these commands in your R session:
install.packages("devtools") # optional, in case you don't have it
require(devtools)
devtools::install_github("kasparmartens/PolyaGamma")
library(PolyaGamma)

Related

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")

Docker build cannot fetch 'R.utils'

In my Dockerfile I have the following lines:
FROM rocker/verse:latest
RUN R -e "install.packages(c('R.utils'), repos = 'https://cran-archive.r-project.org')"
When I run docker build . I got:
> install.packages(c('R.utils'), repos = 'https://cran-archive.r-project.org')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository https://cran-archive.r-project.org/src/contrib:
cannot open URL 'https://cran-archive.r-project.org/src/contrib/PACKAGES'
Warning message:
package ‘R.utils’ is not available (for R version 4.0.2)
I'm new to Docker, not too sure what I'm doing wrong. I put https://cran-archive.r-project.org/src/contrib/PACKAGES in browser and it couldn't load, should I try a different repo URL?
Thanks!
Try any of the advertised mirrors, and they should have the most recent release of R.utils for your version of R-4.0.2.
That CRAN mirror is specifically for old versions of R. Since your version of R (4.0.2) is not old, it is not found there. That cran-archive is intended for R versions without support for those packages (ergo the "archive" label, I suspect).
From the R FAQ 2.10:
Since March 2016, “old” material is made available from a central CRAN archive server (https://CRAN-archive.R-project.org/).
Or perhaps from the R for Mac OS X page:
Package binaries for R versions older than 3.2.0 are only available from the CRAN archive so users of such versions should adjust the CRAN mirror setting (https://cran-archive.r-project.org) accordingly.
Both of these suggest that repos = 'https://cran-archive.r-project.org' should be used for old versions of R, but your error reports R-4.0.2 (not old)
yes, you have to mention the full path to the repo. https://cran.r-project.org/src/contrib/R.utils_2.9.2.tar.gz use this repo link to get R.util.
You can also run the command sudo apt-get install -y r-cran-r.utils to install R.utils

R package ‘ElemStatLearn’ is not available (for R version 3.6.3) is there any alternative available [duplicate]

I typed the following in the R command line:
install.packages("RecordLinkage")
I got the following error:
Warning in install.packages :
package ‘RecordLinkage’ is not available (for R version 3.1.0)
However, one of my coworkers did the exact same thing on the exact same version of R (3.1.0) and it worked. In addition, I've managed to install other packages successfully.
Any idea why this does not work? Any help would be greatly appreciated.
The package has been archived, so you will have to install from an archive.
I know this because the package home page at http://cran.r-project.org/web/packages/RecordLinkage/index.html tells me:
Package ‘RecordLinkage’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2015-05-31 as memory access errors were not corrected.
By following the link to archives (http://cran.r-project.org/src/contrib/Archive/RecordLinkage) I get a list of all old versions:
[ ] RecordLinkage_0.3-5.tar.gz 12-Sep-2011 18:04 688K
[ ] RecordLinkage_0.4-1.tar.gz 12-Jan-2012 09:39 676K
So now I know the version number of the most recent version. The way forward is to download the tarball, install all package dependencies and then install the package from the local downloaded file.
Try this:
# Download package tarball from CRAN archive
url <- "http://cran.r-project.org/src/contrib/Archive/RecordLinkage/RecordLinkage_0.4-1.tar.gz"
pkgFile <- "RecordLinkage_0.4-1.tar.gz"
download.file(url = url, destfile = pkgFile)
# Expand the zip file using whatever system functions are preferred
# look at the DESCRIPTION file in the expanded package directory
# Install dependencies list in the DESCRIPTION file
install.packages(c("ada", "ipred", "evd"))
# Install package
install.packages(pkgs=pkgFile, type="source", repos=NULL)
# Delete package tarball
unlink(pkgFile)
Note:
This will only work if you have the build tools installed on your machine. On Linux this will be the case. But on Windows you will have to install RTools if you don't have it already. And on OS X (Mac) you will have to install XCode and the associated command line tools.
Also this solution from the Rstudio blog
require(devtools)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")
https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages
If using Rstudio, select "install from Package Archive File(.zip;.tar.gz)" in "Install Packages" window.
On linux this is simply:
sudo su - -c "R -e \"devtools::install_url('https://cran.r-project.org/src/contrib/RecordLinkage_0.4-10.tar.gz')\""

install quantstrat for R latest R version ()

I would like to install a package when using the latest R version in RStudio.
In particular the quantstrat package
Is that possible?
This is the R latest version I have 3.4.1
my error message:
Warning in install.packages :
package ‘quantstrat’ is not available (for R version 3.4.1)
Because quantstrat build-fail at R-Forge, you can't get the pre-build file(.tar.gz). You can get the code from github and build by yourself.
install.packages("devtools")
require(devtools)
install_github("braverock/blotter") # dependency
install_github("braverock/quantstrat")
Can you provide the installation code that produced that error message? Are you trying to install it from CRAN?
That doesn't appear possible.
A post from 2014 states it's not on CRAN
quantstrat is a R package ... still under heavy development and can’t be installed from CRAN yet. You can install it from source and the process is straightforward.
It's not on the current list of available CRAN packages
It's R-Forge page states the current version 'Failed to build'.
You could download the previous version (and its dependency) from R-Forge at
http://download.r-forge.r-project.org/bin/windows/contrib/3.2/quantstrat_0.9.1739.zip and
http://download.r-forge.r-project.org/bin/windows/contrib/3.2/blotter_0.9.1741.zip
(or get the Linux tar.gz files). Assuming they're saved in your personal Downloads folder, install it in R with
install.packages("~/Downloads/blotter_0.9.1741.zip", repos = NULL)
install.packages("~/Downloads/quantstrat_0.9.1739.zip", repos = NULL)
According to that first link, you'll need to install these prereqs first, if they're not already:
install.packages("FinancialInstrument")
install.packages("PerformanceAnalytics")
install.packages("foreach")
Edit: see the comment below from #brian-g-peterson for how the current deployment avenue uses GitHub. https://github.com/braverock/quantstrat

Installing older version of R package

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")

Resources