yonicd
yonicd

Reputation: 518

Offline installation of packages in RStudio

I am working on a terminal at work that has no http||https connection due to security protocol. I downloaded manually a few packages on another computer and am trying to install them using RStudio. When I do run in RStudio

install.packages(//filedir/package_file.zip,repos=NULL,type="source")

it is trying to connect to an online repository anyways:

>>warning in istall.packages:
>>unable to resolve 'www.stats.ox.ac.uk'

but when I go through RGui and use utils:::menuInstallLocal() and use the popup window it doesn't try connecting through a server and installs my local files.

What am I doing wrong in RStudio?

I also want to be able to make it that the dependencies and imports install automatically for the parent package when I install it.

Upvotes: 6

Views: 20422

Answers (3)

wishy
wishy

Reputation: 23

Step1:- Install R base(64 bit) and R Studio on PC. Step2:- Insert Pendrive or location on PC where the offline package folder is kept. Step3:-. Open R studio in edit mode(R script).

getDependencies <- function(packs){
  dependencyNames <- unlist(
    tools::package_dependencies(packages = packs, db = available.packages(),
                                which = c("Depends", "Imports"),
                                recursive = TRUE))
  packageNames <- union(packs, dependencyNames)
  # Remove base dependencies, these are installed with R and not published on CRAN
  basePackages <- c("base","compiler","datasets","graphics","grDevices","grid",
                    "methods","parallel","splines","stats","stats4","tcltk","tools","utils")
  packageNames <- setdiff(packageNames, basePackages)

  packageNames
}


 packages <- getDependencies(c("tidyverse", "pacman"))
setwd("E:/offline package R installation")
pkgInfo <- download.packages(pkgs = packages, destdir = getwd(), type = "win.binary")
# Save just the package file names (basename() strips off the full paths leaving just the filename)
write.csv(file = "pkgFilenames.csv", basename(pkgInfo[, 2]), row.names = FALSE)

Step5: after taking desire package in excel sheet as well as packages in a folder take it store it wherever you want. after that open R editor on any other computer.and execute following code

# Set working directory to the location of the package files
setwd("E:/offline package R installation")

# Read the package filenames and install
pkgFilenames <- read.csv("pkgFilenames.csv", stringsAsFactors = FALSE)[, 1]
install.packages(pkgFilenames, repos = NULL, type = "win.binary")

Finally now you can easily use offline package with its deoendancies on any computer without any internet connection

Upvotes: 1

zyduss
zyduss

Reputation: 89

Assuming you have your packages in zip archive format local onto your machine.

RStudio has a simple menu option

Tools>Install Packages > Select "Package Archive File" in Install from option

browse your package file you need to install.

Post installation you may like to load the libraries for instance if you have installed "tm" package then you may run the command

library(tm) # load the library "tm"

Hope it works :)

Upvotes: 6

Pop
Pop

Reputation: 12411

Do not use the argument type="source", since you give a link to a zip file:

This should work

install.packages("yourlink.zip", repos=NULL)

Upvotes: 5

Related Questions