Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

svn - Cannot install R-forge package using install.packages

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...