Last active
September 20, 2017 11:42
-
-
Save andrie/e607a3017ce2113744f3769d44c817f4 to your computer and use it in GitHub Desktop.
Use miniCRAN to install packages on SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Instructions for using miniCRAN to create a package repository for installing packages on SQL Server 2016 | |
# | |
# 1. Create a local repository on a machine connected to the Internet | |
# 2. Copy the miniCRAN repository to the target machine | |
# 3. Install the packages on the target machine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a local miniCRAN repository | |
# | |
# The settings will download windows binary files with R-3.2.x, ready for installation on a SQL Server machine. | |
# Run this code on a machine that has internet connectivity | |
# Install miniCRAN -------------------------------------------------------- | |
if(!require("miniCRAN")) install.packages("miniCRAN") | |
if(!require("igraph")) install.packages("igraph") | |
library(miniCRAN) | |
# Fill out these values to suit your requirements ------------------------- | |
# Define the package source, e.g. your CRAN mirror of choice, or an MRAN snapshot | |
CRAN_mirror <- c(CRAN = "https://mran.microsoft.com/snapshot/2016-04-01") | |
# Define the local download location | |
local_repo <- "~/miniCRAN" | |
# Define the packages you need. You don't need to specify dependencies | |
pkgs_needed <- c("ggplot2", "ggdendro") | |
# Plot the dependency graph ----------------------------------------------- | |
plot(makeDepGraph(pkgs_needed)) | |
# Create the local repo --------------------------------------------------- | |
pkgs_expanded <- pkgDep(pkgs_needed, repos = CRAN_mirror) | |
makeRepo(pkgs_expanded, path = local_repo, repos = CRAN_mirror, type = "win.binary", Rversion = "3.2") | |
# List local packages ----------------------------------------------------- | |
pdb <- as.data.frame( | |
pkgAvail(local_repo, type = "win.binary", Rversion = "3.2"), | |
stringsAsFactors = FALSE) | |
head(pdb) | |
pdb$Package | |
pdb[, c("Package", "Version", "License")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install packages from a local miniCRAN repository | |
# | |
# Run this code on the SQL Server machine | |
pkgs_needed <- c("ggplot2", "ggdendro") | |
local_repo <- "~/miniCRAN" | |
# | |
.libPaths()[1] | |
"C:/Program Files/Microsoft SQL Server/130/R_SERVER/library" | |
lib <- .libPaths()[1] | |
install.packages(pkgs_needed, | |
repos = file.path("file://", normalizePath(local_repo, winslash = "/")), | |
lib = lib, | |
type = "win.binary", | |
dependencies = TRUE | |
) | |
installed.packages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment