How do I install an R package from the source tarball on windows? - r

The forecast package for R has been updated to version 2.12, but there are currently only windows binarys for 2.11 available on CRAN.
How do I install an R package from the source on Windows?

I know this is an old question but it came up first in my Google search for this same question, even though I knew the answer I just wanted something to copy and paste. Which makes it worth improving the answer for future reference. So here is what works for me:
Install rtools, then:
install.packages(path_to_file, repos = NULL, type="source")

Two answers that may help you avoid the hassle of installing Rtools.
Use http://win-builder.r-project.org/ to build a binary version, download it, and install (using install.packages(...,repos=NULL))
If the package has no binary component (i.e. no src directory with C, C++, or Fortran code that needs to be compiled during installation (not true for forecast, but possibly useful some other time) then simply specifying type="source" within the install.packages call (whether from a repository or a local copy of the source tarball (.tar.gz file)) will install the source package, even on Windows.

Start by reviewing the section on Windows packages in the R Installation and Administration manual, then carefully follow the instructions from The Windows toolset appendix.
I know it's usually bad form to mainly provide links in an answer, but these are links to the canonical references on this topic. I simply link to them rather than summarize their contents, since they should be accurate for the most current R release.

I'm not sure if this is the best way, but I found the following method to work (based in part on the answers above):
1) Download the package .tar
2) Move the package to the directory with your user R libraries (e.g., in my case it was "C:/Users/yourUserName/Documents/R/win-library/3.3")
3) Within Rstudio (or elsewhere, probably), run the command... install.packages("packageName.tar", repos=NULL, type="source")
That worked for me at least. Hope it's helpful!

Download the package *.tar.gz.
make sure you have Rtools installed.
Make sure the R and Rtools paths are added in the environment varialble.
Open a command prompt. Type R CMD INSTALL packagename.tar.gz.
it will work i hope.

To install a package from a .tar.gz file, follow these steps:
Launch R to have the R command prompt
Type: install.packages(<path_to_tar.gz_file>, repos = NULL)
or launch directly:
R CMD INSTALL <path_to_.tar.gz_file>
You need to have R installed but you don't need RTools

Related

install cnv-seq.tar.gz in R

I'm trying to install this cnv-seq package on my R library to help copying number variation analysis. However, when I type in
install.packages("cnv-seq")
in R command, an error code pops out saying it is not available for 3.1.1 version. So I tried the old versions as well. All says not available. And I double check with the menu, Packages-> Install packages->. No cnv-seq
Ok. Then I tried to install it from a local source which is the "cnv-seq.tar.gz"
when i type in
install.packages("C:/cnv-seq.tar.gz", repos=NULL, type="source")
it still returns an error that says cannot extract package from this file.
Installation of package had non-zero exit status.
Anything went wrong or is there another I can install this package manually to my PC? After take a look at a similar question here couple years ago,
How do I install an R package from source?
I still could not fix this problem.
This is a case of RTFM ;)
You can do the whole process from within R. Below, we download the archive to the temporary directory, then extract it and finally install it.
download.file('http://tiger.dbs.nus.edu.sg/cnv-seq/cnv-seq.tar.gz',
f <- tempfile())
untar(f, exdir=tempdir())
install.packages(file.path(tempdir(), 'cnv-seq', 'cnv'), type='source', repos=NULL)
I believe you first must untar the file. I believe 7zip has this capability if you do not have access to a linux machine. The linux command would be:
tar -xvf /path/to/file/cnv-seq.tar.gz
After you do this you should be able to import the package into R.

installing package from R-forge fails [duplicate]

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

R CMD INSTALL --build package --> "vignettes missing"

Problem:
C:\>Rcmd.exe INSTALL --build --library=C:/Users/local_aphalo/Documents/R/win-library/3.0 photobiology
C:\>Rcmd.exe INSTALL --build --library=C:/Users/local_aphalo/Documents/R/win-library/3.0 photobiology_0.2.6.tar.gz
The first command (as used by RStudio) builds a ZIP file that is missing the vignettes.
The second command builds a ZIP that includes the vignettes.
Using R CMD instead of Rcmd.exe makes no difference. The .tar.gz was built immediately before attempting to build the .zip file, from exactly the same source files, from within RStudio (which uses Rcmd.exe build photobiology).
The vignettes are coded in .Snw files using knitr, documentation and NAMESPACE use ROxygen2. The problem happens on all of the packages that I have tried to build, but they are very similarly coded. Only one of them uses Rcpp.
When installing the package for use from within RStudio, installing from .tar.gz installs vignettes just fine. If installing from .zip, whether vignettes get installed or not, depends on whether the .zip files contains them or not (which depends on which of the two commands at the top of this message was used to build the .zip file).
I am using R 3.0.1, and also tried a couple of R 3.0.1 patched builds a few days back. I am mostly using Windows 7 (both 32 bit, and 64 bit), I tried once under Ubuntu 64bit, and the problem is reproducible. I first noticed the problem when using RStudio (0.97 and 0.98) and posted a message in the RStudio forum, but have received no answer in a couple of weeks. I have found at least another relatively old post about this problem in the RStudio website forum, but it has not been answered. Today, I investigated a bit further, and the problem is clearly not related to RStudio, as I can reproduce it through the command line.
The question is: Is this behavior a feature? a bug? or I am missing just an option in the command used?
Of course, I can easily work around the problem at the command line by using the .tar.gz file to build the .zip file, but as I think the preferred way of building a package is by just supplying the package name as argument.
Thanks for any insights on the origin of this problem.
I think this is a feature:
if you're installing from source, vignettes are always built
if you're installing from a binary, they're not built, and will only be available if they were built when the binary was made
This approach means that you can distribute vignettes in binary packages to people who might not be able to build them from source.

How can I build a stand alone R engine with some packages included?

I have a windows server that does not allow me to install anything but it allows me to run exe files (Meaning that I cannot simply download the R installation package and install R that way). I want to run R on it and I like to know if it is possible for me to make an R.exe with some packages like ggplot and lattice included?
Do you have any filestore on the server? I can't imagine that you wouldn't have. You can install packages to any directory, which can then be your own personal library. Look at the help(install.packages) and help(library) and there's a lib or lib.loc argument that tells it where to stick it.
If the reason you can't install is because install.packages can't get through the network to CRAN, then download the binary from CRAN, transfer it to the server, and install that way.
Note that I didn't answer your question about building an R exe with bundled packages (here's that answer: "No") because you thought the answer to that question was the solution to your real problem ("I can't install packages"). Always ask a question to your original problem...
I ran across the portable version of R that could do it for me. It generates a folder that can be moved to the new server.
http://sourceforge.net/projects/rportable/

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

Resources