Riya
Riya

Reputation: 193

R package from local drive

I don't have access to internet. Hence, i downloaded sqldf package from other system and then transfer it to this system.

The sqldf_0.4-10.tar file is saved in "C:\Users\Riya\Documents\R" and also saved binary file in the same folder. I want to install the package with dependencies as well. When i am installing the package using "Install Package from local zip file" under "Packages" dropwdown. It is not installing dependencies. I googled solutions and found :

tools::write_PACKAGES("C:/Users/Riya/Documents/R/") 

After that,

install.packages("sqldf", repos="file://C:/Users/Riya/Documents/R/") 

It is giving me an error -

source repository is unavailable to check versions 
Error in read.dcf(file = tmpf) : cannot open the connection 
In addition: Warning message: 
In read.dcf(file = tmpf) : 
cannot open compressed file '//C:/Users/Riya/Documents/R/bin/windows/contrib/3.1/PACKAGES', probable reason 'No such file or directory'> 

It's a window system. Note : tools::write_PACKAGES() creates 2 files. I also deleted "PACKAGES.gz" file as per the solution mentioned in a forum.

Upvotes: 3

Views: 2757

Answers (2)

Amit
Amit

Reputation: 1

Installing multiple packages from local zip files in R [ Windows 7 32 bit and RGui(32bit) i386 3.3.0 ]

*i am not use to in R, even Stack.

In simple way we do ---

  1. Download the ZIP file of the package,save it to local drive of your computer.
  2. Run following R commands

    install.packages(file.choose(), repos=NULL)
    
    • The file.choose() command will show a window allowing you to choose the .zip file or the tar.gz file where you downloaded it.

Now we try to installing multiple packages form local drive ---

  1. Download the ZIP file of the package,save it to local drive of your computer.
  2. Open RGui i386 3.3.0.
  3. In R Console run following commands -

    result <- array(list.files(path = "D:/Backup/R tutorial/downloaded_packages", pattern = "*.zip", all.files = FALSE, full.names = FALSE, recursive = FALSE))
    
    • The result store the the list of zip files name in array until the value replace by any way or close the RGui (work space).
    • The path = "..." replace your own drive path.
    • The pattern = "..." may replace "tar.gz" but i did not test it yet.
  4. Now run the loop to install all zip files:

    for(i in 1:length(result)) {
      x <- paste("D:/Backup/R tutorial/downloaded_packages/",result[i], sep="", collapse = NULL)
      print(i)
      print(result[i])
      install.packages(x, repos = NULL, type = "win.binary")
      # readline(prompt="Press [enter] to continue")
    }
    
    • In x we store the file name, paste help me to do that.
    • install.packages(x, repos = NULL, type = "win.binary") installing the zip file(s) one by one.
    • The readline take input from a user to continue the loop. Here i comment it by #
  5. Normal loop execution -

    [1] 7402   
    [1] "RKEELdata_1.0.3.zip"
    Installing package into ‘C:/Users/Amitava Kar/Documents/R/win-library/3.3’
    (as ‘lib’ is unspecified)
    
  6. Common Error and exit loop -

    [1] 7403
    [1] "RKEELjars_1.0.15.zip"
    Installing package into ‘C:/Users/Amitava Kar/Documents/R/win-library/3.3’
    (as ‘lib’ is unspecified)
    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 'RKEELjars/DESCRIPTION', probable reason 'No such file or directory'
    
    • This error show when the zip file is corrupt or not readable.
    • The print(i) show the number of array read e.g. [1] 7403
    • The print(result[i]) show the zip file e.g. [1] "RKEELjars_1.0.15.zip"
    • now manually download and replace the zip file and change in loop for(i in 1:length(result)) by for(i in 7403:length(result)) and re run the program again e.g.

      for(i in 7403:length(result)) {
      x <- paste("D:/Backup/R tutorial/downloaded_packages/",result[i], sep="", collapse = NULL)
      print(i)
      print(result[i])
      install.packages(x, repos = NULL, type = "win.binary")
      # readline(prompt="Press [enter] to continue")
      }
      

Upvotes: -1

jangorecki
jangorecki

Reputation: 16727

From the R console you can go with:

install.packages("C:/Users/Riya/Documents/R/sqldf_0.4-10.tar", repos=NULL, type="source")

You can also install from OS command line, using R CMD INSTALL as G. Grothendieck wrote in the comment.

Upvotes: 4

Related Questions