boB Rudis
6 years ago
10 changed files with 155 additions and 37 deletions
@ -0,0 +1,63 @@ |
|||
#' Download a standalone version of Chromium (recommended) |
|||
#' |
|||
#' @md |
|||
#' @param path where to store the Chromium app. |
|||
#' @param chromium_revision version to download (keep default unless you require |
|||
#' a specific version) |
|||
#' @export |
|||
download_chromium <- function(path = NULL, chromium_revision = 579032) { |
|||
|
|||
path <- path.expand(path) |
|||
stopifnot(dir.exists(path)) |
|||
|
|||
dl_src_path <-'https://storage.googleapis.com' |
|||
|
|||
list( |
|||
linux= '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip', |
|||
mac = '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip', |
|||
win32 = '%s/chromium-browser-snapshots/Win/%d/chrome-win32.zip', |
|||
win64 = '%s/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip' |
|||
) -> dl_urls |
|||
|
|||
|
|||
dl <- if (unname(Sys.info()["sysname"] == "Windows")) { |
|||
if (unname(Sys.info()["machine"] == "x86-64")) "win64" else "win32" |
|||
} else if (unname(Sys.info()["sysname"] == "Darwin")) { |
|||
"mac" |
|||
} else if (unname(Sys.info()["sysname"] == "Linux")) { |
|||
"linux" |
|||
} else { |
|||
stop("Unrecognized platform", call.=FALSE) |
|||
} |
|||
|
|||
dl_url <- sprintf(dl_urls[[dl]], dl_src_path, chromium_revision) |
|||
dl_fil <- file.path(path, basename(dl_url)) |
|||
|
|||
message("Downloading ", dl_url) |
|||
|
|||
download.file(dl_url, dl_fil, mode="wb") |
|||
on.exit(unlink(dl_fil), add=TRUE) |
|||
|
|||
unzip(dl_fil, unzip = getOption("unzip"), exdir = path) |
|||
for (fil in list.files(path, recursive = TRUE)) Sys.chmod(fil, "0755") |
|||
|
|||
chrome_ex_path <- if (unname(Sys.info()["sysname"] == "Windows")) { |
|||
file.path(path, "chrome-win32", "chrome.exe") |
|||
} else if (unname(Sys.info()["sysname"] == "Darwin")) { |
|||
file.path(path, "chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium") |
|||
} else if (unname(Sys.info()["sysname"] == "Linux")) { |
|||
file.path(path, "chrome-linux", "chrome") |
|||
} |
|||
|
|||
message( |
|||
sprintf( |
|||
"Please set the HEADLESS_CHROME environment variable to:\n '%s'\n\n", chrome_ex_path |
|||
), "This value has also been returned invisibly." |
|||
) |
|||
|
|||
invisible(chrome_ex_path) |
|||
|
|||
} |
|||
|
|||
|
|||
|
@ -1,36 +1,45 @@ |
|||
.onAttach <- function(libname, pkgname) { |
|||
|
|||
HEADLESS_CHROME <- Sys.getenv("HEADLESS_CHROME") |
|||
|
|||
if (interactive()) { |
|||
|
|||
if (Sys.getenv("HEADLESS_CHROME") == "") { |
|||
if (HEADLESS_CHROME == "") { |
|||
|
|||
if (unname(Sys.info()["sysname"] == "Windows")) { |
|||
|
|||
if (unname(Sys.info()["machine"] == "x86-64")) { |
|||
Sys.setenv(HEADLESS_CHROME="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe") |
|||
HEADLESS_CHROME <- "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" |
|||
} else { |
|||
Sys.setenv(HEADLESS_CHROME="C:/Program Files/Google/Chrome/Application/chrome.exe") |
|||
HEADLESS_CHROME <- "C:/Program Files/Google/Chrome/Application/chrome.exe" |
|||
} |
|||
|
|||
} |
|||
|
|||
if (unname(Sys.info()["sysname"] == "Darwin")) { |
|||
Sys.setenv(HEADLESS_CHROME="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome") |
|||
HEADLESS_CHROME <- "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" |
|||
} |
|||
|
|||
if (unname(Sys.info()["sysname"] == "Linux")) { |
|||
Sys.setenv(HEADLESS_CHROME="/usr/bin/google-chrome") |
|||
HEADLESS_CHROME <- "/usr/bin/google-chrome" |
|||
} |
|||
|
|||
} |
|||
|
|||
if (file.exists(HEADLESS_CHROME)) { |
|||
Sys.setenv("HEADLESS_CHROME"=HEADLESS_CHROME) |
|||
packageStartupMessage( |
|||
sprintf( |
|||
"Set Chrome binary to [%s]. |
|||
To override, pass in manually to functions or use decapitated::set_chrome_env()", |
|||
Sys.getenv("HEADLESS_CHROME")) |
|||
sprintf("Using Chrome binary from [%s].\n", Sys.getenv("HEADLESS_CHROME")) |
|||
) |
|||
} else { |
|||
packageStartupMessage( |
|||
sprintf("Chrome binary not found at [%s].\n", Sys.getenv("HEADLESS_CHROME")), |
|||
"Please use decapitated::download_chromium() and set the HEADLESS_CHROME ", |
|||
"environment variable to the value returned from the function." |
|||
) |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/download-chromium.R |
|||
\name{download_chromium} |
|||
\alias{download_chromium} |
|||
\title{Download a standalone version of Chromium (recommended)} |
|||
\usage{ |
|||
download_chromium(path = NULL, chromium_revision = 579032) |
|||
} |
|||
\arguments{ |
|||
\item{path}{where to store the Chromium app.} |
|||
|
|||
\item{chromium_revision}{version to download (keep default unless you require |
|||
a specific version)} |
|||
} |
|||
\description{ |
|||
Download a standalone version of Chromium (recommended) |
|||
} |
Loading…
Reference in new issue