Installing an R package from local unzipped folder
Asked Answered
H

7

30

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?

Haddad answered 31/3, 2017 at 22:48 Comment(0)
L
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.

Lemur answered 2/4, 2017 at 8:46 Comment(0)
E
51

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")
Ecotype answered 27/5, 2018 at 7:2 Comment(1)
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").Siriasis
P
8

I was able to do this using devtools:

devtools::install("path/to/package/folder")
Penalty answered 14/8, 2021 at 14:11 Comment(0)
C
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")
Charmeuse answered 31/3, 2017 at 23:56 Comment(2)
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?Haddad
I am pretty sure you can't do that. But you can rebuild your package from the command line using: R CMD build MY_PACKAGECharmeuse
L
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.

Lemur answered 2/4, 2017 at 8:46 Comment(0)
D
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")
Diseuse answered 10/3, 2018 at 17:21 Comment(0)
C
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

Cabinet answered 23/8, 2020 at 3:27 Comment(0)
M
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.

Mudslinging answered 11/4, 2023 at 11:1 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.