Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbarton/8ff0533ec20387c9c0a4 to your computer and use it in GitHub Desktop.
Save michaelbarton/8ff0533ec20387c9c0a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env Rscript
# Assume that the libraries are installed in "../vendor/r/"
# Adjust this path to the relative path between the script
# and the packrat directory
set_package_environment <- function(args){
dir <- dirname(sub("--file=", "", args[grep("--file", args)]))
libs <- file.path(dir, "..", "vendor", "r", "packrat", "lib", "*", "*")
.libPaths(c(.libPaths(), libs))
}
args <- commandArgs(trailingOnly = FALSE)
set_package_environment(args)
# Load an example package
library(tidyr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment