46

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?

1
  • 4
    The binary simply hasn't been picked up by your mirror yet. Get the forecast_2.12 Windows binary from the main CRAN repository, or wait a day for the mirror to update. Commented Jan 19, 2011 at 19:50

6 Answers 6

93

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")
3
  • Thank you for coming back to the question!
    – Zach
    Commented Jul 8, 2015 at 17:06
  • 6
    You just need Rtools; devtools is unnecessary. install.packages is from utils, which is distributed with R. Commented Jul 8, 2015 at 19:12
  • Yes, of course you're right @JoshuaUlrich, and I've amended accordingly. Commented Jul 8, 2015 at 22:28
9

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.

3
  • 4
    So the answer appears to be "very carefully." Thanks for the information!
    – Zach
    Commented Jan 19, 2011 at 20:14
  • 1
    More accurately. Read the Manual. Don't guess.
    – IRTFM
    Commented Jan 20, 2011 at 1:57
  • 1
    You can't break anything, so just go ahead. Commented Jan 20, 2011 at 9:05
8

Two answers that may help you avoid the hassle of installing Rtools.

  1. Use http://win-builder.r-project.org/ to build a binary version, download it, and install (using install.packages(...,repos=NULL))
  2. 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.
5
  1. Download the package *.tar.gz.
  2. make sure you have Rtools installed.
  3. Make sure the R and Rtools paths are added in the environment varialble.
  4. Open a command prompt. Type R CMD INSTALL packagename.tar.gz.

it will work i hope.

1
  • I am not quite sure i get number 3. How would I add the Rtools path in the environment variable? install.packages(....,environment=(rtools=<path>))? Commented Apr 24, 2013 at 7:44
5

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!

3

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.