Installing an R package from local unzipped folder - r

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?

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")

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")

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.

I was able to do this using devtools:
devtools::install("path/to/package/folder")

If you have zip file, you can install as follows
install.packages("E:\\R-Packages\\plyr_1.8.4.zip", repos = NULL, type="source")

Go to R-studio
Click the install icon in the packages section found in the right side of the window
A new window pops up
Set "Install from: Package Archive file" "Package Archive: Browse the unzipped file and select it"
Click install
This installs the package to the R library

Related

Loading packages installed from a local .zip file

I am trying to load a self-written package in order to use the functions I created there without having to copy and paste them into each new project. The program is having difficulties to recognize the package though. These are the lines I am inputting and the messages issued by the system.
> .libPaths(c(.libPaths(), "path-to-package"))
> install.packages("somepath/myPackage.zip", repos = NULL, lib = "path-to-package")
> library("myPackage", lib.loc = "path-to-package")
Error in library("myPackage", lib.loc = "path-to-package") :
‘myPackage’ ist keine gültiges installiertes Paket
After issuing "install.packages", new directories and files are displayed in Microsoft Explorer. While other files vanish at the end, the directory named "myPackage" remains.
Would it be easier to try and get R do my bidding and make it recognize myPackage as a package not only when installnig, but also when loading it? Or is it easier to copy and paste the functions from the package when I need them?
I do own the book "R Packages" by Hadley Wickham in its first edition from 2015. Are there any passages I might want to reread to get going?

offline installation of packages in R - empty index file generated

I am trying to install packages on a remote windows machine with no internet connection using source packages. I am trying to follow the instructions given in an answer to the previous question
Offline install of R package and dependencies
I have a folder with .tar.gz files for the package and it's dependencies. I run the commands
library(tools)
write_PACKAGES()
which generates the PACKAGES and PACKAGES.gz in the same folder. However, my PACKAGES file is empty (with size 0 KB).
When I try to install the package using
install.packages("<PACKAGE_NAME>", contriburl = "file:///")
(I am in the same directory as all the source files), I am getting the following error
cannot open compressed file '//PACKAGES', probable reason 'No such file or directory'
I am not sure if there is something wrong with the way I specify the path or is it because my PACKAGES file is empty that I am getting this error.
Any help here would be great!
Additional info - The remote machine is a Windows machine and I have also tried deleting the PACKAGES.gz file before installing (as recommended in the link above), but did not succeed.
Thanks!
SN248
I was able to install the package that I wanted (package name = dplyr), using the hints in the comments above. I needed to change two things
I downloaded windows binaries instead of source files, using type = "win.binary" parameter in the download.packages command.
The path in contriburl = "file:///" needed to be changed to contriburl = "file:///<ABSOLUTE_PATH_TO_FOLDER_WITH_WIN_BINARIES>"
With these changes, the package installation went successfully.
Hope it helps others.
SN248

Installing gdata in R

I tried to install package gdata with the following command, but got the message that follows:
install.packages(pkgs="gdata")
Warning in install.packages(pkgs = "gdata") :
'lib = "C:/Program Files/R/R-3.1.3/library"' is not writable
Error in install.packages(pkgs = "gdata") : unable to install packages
Seems the directory "library" should be writable, so what did I do wrong?
You can install in a custom folder by specifying the lib argument of install.packages. Try something like lib = "C:/Users/you/Documents/R/3.1.3/" or whatever folder you have writable.
If R is installed on a Remote Desktop, or somewhere else where R is having difficulty automatically installing those folders, you will need to specify where to put the files. The first step will be creating these folders, for example in your C:/ or D:/ drive. Preferably create an R folder, with a version folder (3.1.3) that you will be using. To know which version of R your using if using R studio, hold control while opening R studio.
Once these folders are created, just use the following code, inputting your path to the version folder (3.1.3). For example:
lib = "D:/R/3.1.3"
install.packages("gdata", lib)
And then to load your package.
library("gdata", lib.loc= lib)

Install ggplot2 from local directory

I need to download packages and install from local directory. But I'm having trouble installing ggplot2. I get no warning, but it seems the library is not installed. Output is below, any suggestions? Operating system is Windows. After running, the directory C:...\R\win-library\3.1 contains subdirectory ggplot2-master.
> install.packages("C:/.../packages/ggplot2-master.zip", repos = NULL, type="source")
Installing package into ‘C:/.../R/win-library/3.1’
(as ‘lib’ is unspecified)
> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’
The correct action was to download the binaries instead of the source.
Note, the following command prompts for the file path:
install.packages(file.choose(), repos=NULL)
The computer is behind a firewall, so the install.package command does not work. I should have downloaded the binary install, but downloaded the source by mistake. So, the corrective action is to download the binary files. I want to point out that in my notes on R, it clearly states to download the binary file. Part of the joys of getting older, not remembering why I came into this room.... Also, rambling...

Unable to install ggplot2

I'm having trouble installing ggplot2 into R. I've looked around here and haven't seen the same error that I'm getting.
> install.packages('ggplot2', dep=TRUE)
Warning in install.packages("ggplot2", dep = TRUE) :
'lib = "C:/Program Files/R/R-2.13.1/library"' is not writable
Error in install.packages("ggplot2", dep = TRUE) :
unable to install packages
Can anybody help?
It would actually suffice to invoke as follows:
> install.packages('ggplot2', dep=TRUE, lib=NULL)
and R should substitue lib with the default location, as in my comment.
Or you could change the environment variable itself.
R needs to have write access to your library to install a package there. The other advice you're getting is good and should be preferred, but you can run R (or RStudio) as an administrator (right-click on the .exe and "Run as Administrator" is an option) which should give it write access to your library.
In RStudio:
Try going to "Tools";
At the top you have "Install packages", click on that;
Then click on "Install to Library", change that to another library and save there.

Resources