29

I am having difficulty installing an unzipped package on a Windows 7 computer without administrative privileges and no internet access. I am using the RGui (not RStudio).

Right now I have an unzipped library sitting in a directory. Unfortunately, when I try:

install.packages("C://path//to//directory", 
    repos = NULL, 
    lib = "C://path//to//newDirectory")

I am getting the error:

Warning in `install.packages("C://path//to//directory",`   :
   'lib = "C://path//to//newDirectory"' is not writable

Which is strange because I do have write privileges to where I am attempting to store the package.

When I get this error, I also get a popup from RGui:

Would you like to use a personal library instead?

If I click Yes, it throws the error:

Error in `install.packages("C://path//to//directory",`   :
    type == "both" cannot be used with 'repos = NULL'

I also cannot install devtools. Any ideas?

Thomas
  • 43,637
  • 12
  • 109
  • 140
Phantom Photon
  • 768
  • 2
  • 10
  • 20

7 Answers7

49

The solution to installing a package that's been unzipped into a folder is as follows:

install.packages("C:/path to folder with the package", 
repos = NULL, 
type = "source")
cs95
  • 379,657
  • 97
  • 704
  • 746
Logit
  • 551
  • 4
  • 9
  • `type = "source"` is the default on Linux but not on Windows platforms. System information used by `install.packages()` to determine default installation parameters `getOption("repos")` and `getOption("pkgType")`. – Paul Rougieux Sep 30 '21 at 10:02
7

I think the error message is actually just wrong. You need to give the file name of the package, not just the directory.

install.packages("C://path//to//directory//MY_PACKAGE.tar.gz", 
    repos = NULL, 
    lib = "C://path//to//newDirectory")
thc
  • 9,527
  • 1
  • 24
  • 39
  • Thanks for the reply! The issue is I no longer have the compressed package, I'm wondering if I can do it on a folder instead of a tar.gz? – Phantom Photon Mar 31 '17 at 23:58
  • I am pretty sure you can't do that. But you can rebuild your package from the command line using: R CMD build MY_PACKAGE – thc Apr 01 '17 at 02:39
6

If it is an unzipped Windows binary (e.g., from CRAN), you can just copy and paste the entire package directory into your library folder. You could also, presumably, use file.copy() to do so if you wanted to do it within R. install.packages() is failing (weirdly) because you're giving it something other than the typical package source or zipped binary that it is expecting.

Thomas
  • 43,637
  • 12
  • 109
  • 140
5

I was able to do this using devtools:

devtools::install("path/to/package/folder")
Jeff Bezos
  • 1,929
  • 13
  • 23
3

If you have zip file, you can install as follows

install.packages("E:\\R-Packages\\plyr_1.8.4.zip", repos = NULL, type="source")
Orhan Celik
  • 1,513
  • 15
  • 12
1
  1. Go to R-studio

  2. Click the install icon in the packages section found in the right side of the window

  3. A new window pops up

  4. Set "Install from: Package Archive file" "Package Archive: Browse the unzipped file and select it"

  5. Click install
    This installs the package to the R library

David Buck
  • 3,752
  • 35
  • 31
  • 35
1

If it is a package that has been removed from the repo but you have an installed version (and want to e.g. move it), you can do this in RStudio on Windows:

  1. zip the folder in which the package currently is (using any of the usual programs, 7zip, etc.)
  2. move it to a folder accessible from the R version you want to install to
  3. in RStudio click on Tools->Install packages and choose "Package Archive File (zip; tar.gz)" in the "Install from" dropdown.

I have just managed to move an obsolete package using this method and it can be loaded as expected.

Reader 123
  • 285
  • 1
  • 7