4

I'm trying to install package rpart for R-2.14.0 on Windows 7, but I get the warning:

package ‘rpart’ is not available (for R version 2.14.0)

So I download the tar.gz file from the package page. I have installed Rtools but I disabled all the options, including the one that changes the PATH. Then I do the following:

> install.packages("C:/rpart_3.1-50.tar.gz", type="source")
Installing package(s) into ‘C:/Users/backupSam/Documents/R/win-library/2.14’
(as ‘lib’ is unspecified)
inferring 'repos = NULL' from the file name
* installing *source* package 'rpart' ...
** libs

*** arch - i386
ERROR: compilation failed for package 'rpart'
* removing 'C:/Users/backupSam/Documents/R/win-library/2.14/rpart'
* restoring previous 'C:/Users/backupSam/Documents/R/win-library/2.14/rpart'
Warning messages:
1: running command 'C:/PROGRA~1/R/R-214~1.0/bin/i386/R CMD INSTALL -l "C:/Users/backupSam/Documents/R/win-library/2.14"   "C:/rpart_3.1-50.tar.gz"' had status 1 
2: In install.packages("C:/rpart_3.1-50.tar.gz", type = "source") :
  installation of package ‘C:/rpart_3.1-50.tar.gz’ had non-zero exit status

Any suggestions?

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
screechOwl
  • 27,310
  • 61
  • 158
  • 267
  • 4
    May be a silly question, but have you checked that you have everything discussed [here](http://cran.at.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset)? – joran Nov 07 '11 at 20:27
  • I'll be honest, I haven't but I'm lost/scared when it starts discussing setting the PATH. I ran the install for RTools without making any changes to the PATH or any other options. R and RTools are in separate directories though. – screechOwl Nov 07 '11 at 20:43
  • I sympathize, but won't be much further help (my only experience is on OS X). All I can offer is that you should start Googling, and be scared enough about changing PATH to be very sure you know how to change it back, but not too scared to try at all. – joran Nov 07 '11 at 20:51
  • 2
    @acesnap: you _must_ put the location of Rtools in your path to be able to install packages from source. If you don't want to change it (semi) permanently, just open a cmd window, set the path, and run `R CMD INSTALL`. As it says in the link joran posted _"This appendix contains a lot of prescriptive comments. They are here as a result of bitter experience. Please do not report problems to the R mailing lists unless you have followed all the prescriptions."_ – Joshua Ulrich Nov 07 '11 at 21:01
  • 1
    You will need to change the PATH, but that part is not too bad. You just need to: (1) Right click on 'My Computer'; (2) Left click Properties; (3) Left click the 'Advanced' tab'; (4) Left click 'Environment Variables'; (5) Left click 'Path' in the 'System variables box; (6) Click 'Edit'; (7) Copy the contents of 'Variable value', and save it to a text file, so you can restore the value if you screw it up. Then, follow the instructions at the site @joran directed you to. I agree -- it's very intimidating before you do it -- but it does work, and it's worth taking the plunge. – Josh O'Brien Nov 07 '11 at 21:06
  • possible duplicate of [How do I install an R package from the source tarball on windows?](http://stackoverflow.com/questions/4739837/how-do-i-install-an-r-package-from-the-source-tarball-on-windows) – Joshua Ulrich Nov 07 '11 at 21:08
  • @JoshO'Brien: I find it much "safer" to just run `set PATH=c:\Rtools\bin;c:\Rtools\MinGW\bin;c:\MiKTeX\miktex\bin;c:\R\bin\i386;c:\windows;c:\windows\system32;%PATH%` in a new command window. Then you can't accidentally change anything (semi) permanently. – Joshua Ulrich Nov 07 '11 at 21:11
  • @JoshuaUlrich -- Glad I jumped in, or I wouldn't have learned that. Though I'll still need to go in from time to time to update R versions etc. by hand, I imagine. – Josh O'Brien Nov 07 '11 at 21:16
  • @JoshO'Brien: You could also try something like: `Sys.setenv(PATH=paste("c:\\Rtools\\bin;c:\\Rtools\\MinGW\\bin;c:\\MiKTeX\\miktex\\bin;c:\\R\\bin\\i386;c:\\windows;c:\\windows\\system32",Sys.getenv("PATH"),sep=";"))` in your R session... but I haven't tested that (I don't do a lot of work on Windows). – Joshua Ulrich Nov 07 '11 at 21:19
  • @JoshuaUlrich: That did it. And I didn't have to change the path. Thank you very much. If you paste it in an answer, I'll choose it. Thanks to everyone for your help. – screechOwl Nov 07 '11 at 22:39
  • A bit late, but `rpart` is part of the base R distribution, so you shouldn't have to install it anyway. – Hong Ooi Nov 08 '11 at 01:33

1 Answers1

8

Since you have to set the PATH, but you're hesitant to do so because you're afraid you may hose something up, you can do it temporarily in your R session via:

pathRtools <- paste(c("c:\\Rtools\\bin",
  "c:\\Rtools\\MinGW\\bin",
  "c:\\MiKTeX\\miktex\\bin",
  "c:\\R\\bin\\i386",
  "c:\\windows",
  "c:\\windows\\system32"), collapse=";")
Sys.setenv(PATH=paste(pathRtools,Sys.getenv("PATH"),sep=";"))
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • This is also useful when you have multiple R installations on Windows and need to install a different Rtools for each of them. – Bob Jansen Mar 20 '12 at 14:13