Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing packages onto R

For some reason I am suddenly not able to install packages in R (I have subsequently updated to the latest version of R and am running Windows 7). For example, if I type:

install.packages('beeswarm')

Installing package into ‘D:/Rlibs’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip' Content type 'text/html' length unknown opened URL downloaded 1859 bytes

Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open the connection In addition: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'beeswarm/DESCRIPTION', probable reason 'No such file or directory'

I have read that in Windows 7 there can be important restrictions on rights to writing to certain folders etc. so I've gone to some lengths to install R and library folders in non-default areas of my computer, and to allow myself rights to certain folders, but to no avail. Possibly also of importance is when I type:

.libPaths()

# [1] "D:/Rlibs"                                             
# [2] "C:/Users/L.Halsey/Documents/R/win-library/3.0"        
# [3] "C:/Users/L.Halsey/Documents/Documents/R-3.0.1/library"

I have created several folders in an attempt to create one that I could successfully install libraries into and set them up to be recognised by R using 'environment variables' from the start button. I don't know how to delete any of them though - not sure if this is relevant to my overall problem of not now being able to install/update packages for some reason.

like image 891
user2407346 Avatar asked May 21 '13 22:05

user2407346


People also ask

How do I install packages in R?

Open R via your preferred method (icon on desktop, Start Menu, dock, etc.) Click “Packages” in the top menu then click “Install package(s)”. Choose a mirror that is closest to your geographical location. Now you get to choose which packages you want to install.

How do you install and load the packages in R?

In R, you can easily install and load additional packages provided by other users. or click Tools > Install packages. Write the package name in the dialog, then click install. Once you install the package, you need to load it so that it becomes available to use.

How do you install a package in R explain with example?

In Windows, you get the package menu and install option which is very easy. After selecting a local mirror site, a list of available binary packages is being shown. You can choose the ones you need. Once you have selected the packages you need, you need to click the OK button to download and install them into R.


4 Answers

The error being reported is inability to open a connection. In Windows that is often a firewall problem and is in the Windows R FAQ. The usual first attempt should be to run internet2.dll. From a console session you can use:

setInternet2(TRUE)

(You are correct in thinking this is not due to your library setup. The error says nothing about permissions.) I don't think just typing .libPaths should return that character vector since on my machine I would need to type .libPaths() to see something like that. If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values. This would pick the second and third of the existing paths

 .libPaths( .libPaths()[2:3] )

The inner call retrieves the path vector and the outer call sets it to a reduced vector.

like image 170
IRTFM Avatar answered Oct 18 '22 05:10

IRTFM


Running RStudio as administrator fixed it for me!

like image 29
Malik Gwandu Avatar answered Oct 18 '22 05:10

Malik Gwandu


I will probably duplicate a lot of other answers on the stackoverflow, but I got exactly the same error as OP, namely: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'

Turned out, while I as a user had permissions to write in a certain directory, R did not. In order to be sure you don't have something similar, do following:

  1. get a usb drive, let's name it E
  2. download package source as a .zip file and store it onto usb-drive in some directory, let's name it E:/source
  3. Create directory for libraries on the usb drive, let's name it E:/libs
  4. Install packages calling R command install.package from the R console and setting all relevant directories to point to your usb drive:

    (here I use package zoo as an example)

    install.packages("E:/source/zoo_1.7-12.zip", 
                     destdir = 'E:/source',  # no "/" after the path
                     lib = 'E:/libs', 
                     repos = NULL)
    
  5. Load the package from the directory, where you installed it: library('zoo', lib.loc = 'E:/libs')


After you are sure, it works this way on your usb drive, you can start resolving directories permissions, and try out by changing the paths in the code above.

update: In some windows environments even your usb-stick might be protected from read-write by the R. Make sure you check the permissions using the machine you are working from.

like image 39
Ufos Avatar answered Oct 18 '22 03:10

Ufos


The following worked for me (based on the answer above)

install.packages("clustvarsel", lib = "C:/Users/dnentchev/My Programs/R-3.2.2/library")
like image 35
Dimitar Nentchev Avatar answered Oct 18 '22 05:10

Dimitar Nentchev