Cannot install R-forge package using install.packages
Asked Answered
F

4

66

This, question, is, asked, over, and, over, and, over, on the R-sig-finance mailing list, but I do not think it has been asked on stackoverflow.

It goes like this:

Where can I obtain the latest version of package XYZ that is hosted on R-forge? I tried to install it with install.packages, but this is what happened:

> install.packages("XYZ",repos="http://r-forge.r-project.org")
Warning message: package ‘XYZ’ is not available (for R version 2.15.0)

Looking on the R-forge website for XYZ, I see that the package failed to build. Therefore, there is no link to download the source. Is there any other way to get the source code? Once I get the source code, how can I turn that into a package that I can load with library("XYZ")?

Fillister answered 19/6, 2012 at 16:16 Comment(2)
THANK YOU, @GSee. S.O. is much easier to search and I knew it must have been asked a zillion times.Ames
Windows users should additionally read this: cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolsetAmes
F
54

R-Forge may fail to build a package for a few different reasons. It could be that the documentation has not been updated to reflect recent changes in the code. Or, it could be that some of the dependencies were not available at build time.

You can checkout the source code using svn. First, search for the project on the R-Forge website and go to the project home page -- for example http://r-forge.r-project.org/projects/returnanalytics/ Click the SCM link to get to a page like this http://r-forge.r-project.org/scm/?group_id=579

This page will tell you the command to use to checkout the project. In this case you get

This project's SVN repository can be checked out through anonymous access with the following command(s).

svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/

If you are on Windows, you probably want to download and install TortoiseSVN

Once you have installed TortoiseSVN, you can right click in a Windows Explorer window and select "SVN checkout". In the "URL of repository:" field, enter everything except the "svn checkout " part of the command that you found on R-Forge. In this case, you'd enter "svn://svn.r-forge.r-project.org/svnroot/returnanalytics/".

When you click OK, the project will be downloaded into the current directory.

If you are on a UNIX-alike system (or if you installed the command line client tools when you installed TortoiseSVN for Windows, which is not the default), you can type the command that R-forge gave you in your terminal (System terminal, not the R terminal)

svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/

That will create a new directory under the current working directory that contains all of the files in the package. In the top level of that directory will be a subdirectory called "pkg". This particular project (returnanalytics) contains more than one package.

ls returnanalytics/pkg
#FactorAnalytics  MPO  PApages  PerformanceAnalytics  PortfolioAnalytics

But some R-forge projects only have a single package. e.g.

svn checkout svn://svn.r-forge.r-project.org/svnroot/random/
#Checked out revision 14.
ls random/pkg
#DESCRIPTION  inst  man  NAMESPACE  R

Now that you have a local copy all of the code, if you would like to be able to install the package, you have to build it first.

A WORD OF CAUTION: Since R-Forge failed to build the package, there is a good chance that there are problems with the package. Therefore, if you just build it, you may find that some things do not work as expected. In particular, it is likely that there is missing or incomplete documentation.

If you are on a UNIX-alike system, the package can be built and installed relatively easily. For a multi-package project like returnanalytics, if you want to install, e.g. the PortfolioAnalytics package, you can do it like this

R --vanilla CMD INSTALL --build returnanalytics/pkg/PortfolioAnalytics 

"PortfolioAnalytics" is the name of the directory that contains the package that you want to build/install. For a single-package project, you can build and install like this

R --vanilla CMD INSTALL --build random/pkg

If you would like to build/install a package on Windows, see this question and follow the two links that @JoshuaUlrich provided

More information can be found in R Installation and Administration, the R-Forge User Manual, and the SVN manual.

Fillister answered 19/6, 2012 at 16:16 Comment(10)
The use of --vanilla is probably not necessary depending on what is in .Rprofile. See stackoverflow.com/a/11639336Fillister
INSTALL --build builds a binary version of the package, but does not install it. Also, it'd be easier to do install.packages("XYZ",repos="http://r-forge.r-project.org", type = "source")Creeper
@Creeper R CMD build builds a package without installing it. R CMD INSTALL --build does install it; try for yourself. As for install.packages(..., repos="http://r-forge...", type="source"), perhaps you should read the question again.Fillister
Wow, it does. The documentation is very unclear! (I don't see an option to build an binary package with R CMD build) And why do you need --build for this answer? I also don't see why install.packages + type = "source" is worse than an svn checkout + R CMD installCreeper
svn checkout + install.packages with repos=NULL is fine, but since we're already on the command line for the svn checkout part, I just installed it from there. That is a really good question about --build. I thought that R CMD INSTALL --build myPackage was equivalent to R CMD build myPackage followed by R CMD INSTALL myPackage_1.0.tar.gz. However, after some testing, I see that they are not the same -- .Rbuildignore does not seem to be honored with R CMD INSTALL --build myPackage.Fillister
@Creeper Regarding no option to build a binary with R CMD build, R NEWS from 2.14.0 has an entry that says "R CMD build --binary is now formally deprecated: R CMD INSTALL --build has long been the preferred alternative."Fillister
I think R CMD install --build installs the package, and then makes a compressed copy - which causes a bug in devtools (github.com/hadley/devtools/issues/335) so I'm glad I commented here!Creeper
HTTP is deprecated for all GitHub requests and are 301 redirected to HTTPS equivalents. Some libraries don't handle that well, so trying an HTTPS eqivalent may be helpful in diagnosing this as I did with a curl -i over in another SO question about GitHub and RSwinton
@GSee, I ran the code R --vanilla CMD INSTALL --build returnanalytics/pkg/PerformanceAnalytics/ , but error occurs: > * installing to library ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’ > * installing source package ‘PerformanceAnalytics’ ... > ** libs > gfortran-4.8 -fPIC -Wall -g -O2 -c momentF.f90 -o momentF.o > make: gfortran-4.8: No such file or directory > make: *** [momentF.o] Error 1 > ERROR: compilation failed for package ‘PerformanceAnalytics’ How could I correct it? ThanksJenelljenelle
@Kenny Not sure, but I think you need to install tools: cran.r-project.org/bin/macosx/toolsFillister
R
3

If (and only if) you have the appropriate toolchain for your OS, then this may succeed:

# First download source file to your working directory
# As an example use browser to download pkg:partykit from: 
#  http://download.r-forge.r-project.org/src/contrib/partykit_1.1-2.tar.gz
# Move to working directory
# Or in the case of returnanalytics (which is a bundle of packages):
# http://r-forge.r-project.org/R/?group_id=579 and download the tar.gz (source)
# Then in R:

install.packages( "partykit_1.1-2.tar.gz", repo=NULL, type="source")
# for the first of the ReturnAnalytics packages:
install.packages( "Dowd_0.11.tar.gz", repo=NULL, type="source")

These direction should be "cross-platform". I'm not sure the directions in the accepted answer are applicable to Macs (OSX). (I later confirmed that they do "work" on a Mac but found the process more involved that what I suggested above. They do result in a directory that do contain the packages in a form that should succeed with R --vanilla CMD INSTALL --build pathToEachPackageSeparately)

Ragsdale answered 12/3, 2017 at 1:41 Comment(0)
B
2

It is also possible that the current version of the package you are trying to install requires a newer version of R, for example, you may see error like:

"ERROR: this R is version 2.15.0, package 'PerformanceAnalytics' requires R >= 3.0.0"

then you can try to update your R

or, if you are facing the same situation with me, which is trying to use pqR (currently using R version 2.15), you can find the out-of-date achieved package here:

http://cran.at.r-project.org/src/contrib/Archive/PerformanceAnalytics/

You can get here from R-Forge packages page -> "Stable Release: Get PerformanceAnalytics 1.4.3541 from CRAN" -> Old sources: PerformanceAnalytics archive

for example, you will find package PerformanceAnalytics version 1.1.0 just requires R >= 2.14

Good luck

Bemean answered 9/10, 2014 at 8:46 Comment(0)
S
0

Alternatively, you can install the particular package from GitHub, if it has a repo at GitHub.

I ran install.packages('ggfortify'), and got

Warning message: “package ‘ggfortify’ is not available (for R version 3.3.2)”

ggfortify was the GitHub repo for the same package.

The devtools library allows you to install a package from GitHub directly with install_github('username/repo').

library(devtools)
install_github('sinhrks/ggfortify')
Strange answered 1/2, 2018 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.