DeployR: How to install R packages

430 views Asked by At

I'm using DeployR for Microsoft R Server 2016, 8.0.5 for Windows.

I would like to install package XLConnect for work with Excel files:

> install.packages("XLConnect")
package 'XLConnect' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Windows\Temp\RtmpYnppvI\downloaded_packages

> library("XLConnect")
Console Error there is no package called 'XLConnect'
API Error there is no package called 'XLConnect'

What could be wrong? Thank you.

1

There are 1 answers

9
akrun On

If we are working with deployR, there is a package named deployrUtils which already has the deployrPackage function to load and install the package (if not present)

library(deployrUtils)
deployrPackage("XLConnect")

Below is the code snippet for deployrPackage

deployrPackage <- function(pkgs, lib, repos = getOption("repos"), ...) {
  #
  # this function checks to see if the declared pkgs are installed. If not, 
  # pkgs are installed. In all cases the packages are loaded
  #
  if (!suppressWarnings(require(pkgs, character.only = TRUE))) {
    install.packages(pkgs, lib, repos = repos, ...)
    if(!suppressWarnings(require(pkgs, character.only = TRUE))) {
      stop("Package not found")
    }
  }

  suppressWarnings(require(pkgs, character.only = TRUE))
}

More info about the different functions in deployrUtils can be found here