I\'m trying to port some packages to an R installation on an offline (Windows) computer.
From CRAN (let\'s say data.table), the process: 1) download .zip
The following function extracts a GitHub .zip file located at path to a temporary directory and installs the package straight from there, i.e. does not create an interim .tar.gz archive. The function tries to guess the package name but it can also be given through pkg. Temporary files are removed at exit.
This function does not install any dependencies.
install_zip <- function(path,
pkg = sub("(-[^-]+)?\\.[^.]+$", "", basename(path))) {
dir1 <- tempfile()
dir2 <- file.path(dir1, pkg)
dir.create(dir2, recursive = TRUE)
on.exit(unlink(dir1, recursive = TRUE, force = TRUE))
suppressMessages(unzip(path, exdir = dir2,
unzip = getOption("unzip")))
temp_contents <- dir(dir2)
if (length(temp_contents) == 1L) {
dir3 <- file.path(dir2, temp_contents)
if (file.info(dir3, extra_cols=FALSE)[["isdir"]]) {
dir2 <- file.path(dir2, pkg)
file.rename(dir3, dir2)
}
}
install.packages(dir2, repos = NULL, type = "source")
}