From 34023fc086377ed363e5a5594f1a18f443c99a15 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sun, 13 Jan 2019 13:13:50 -0500 Subject: [PATCH 1/8] cleanup & travis --- .travis.yml | 10 ++-------- NAMESPACE | 6 ++++++ NEWS.md | 4 ++++ R/splashr.r | 28 +++++++++++++++++++++++++++- R/user-agents.R | 20 ++++++++++++++++++++ man/print.splashr.Rd | 20 ++++++++++++++++++++ man/splash.Rd | 8 ++++++-- man/splash_user_agent.Rd | 15 +++++++++++++++ 8 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 man/print.splashr.Rd diff --git a/.travis.yml b/.travis.yml index 756c505..a88a792 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,17 +9,11 @@ services: env: global: - NOT_CRAN=true - matrix: - - PIP="pip" RETICULATE_PYTHON="/usr/bin/python" - - PYTHON=3 PIP="pip3" RETICULATE_PYTHON="/usr/bin/python3" before_install: - - docker pull scrapinghub/splash:3.0 - - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.0 + - docker pull scrapinghub/splash:3.2 + - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.2 - docker ps -a - - sudo apt-get -y install python${PYTHON}-pip python-dev python${PYTHON}-numpy - - sudo $PIP install -U setuptools - - sudo $PIP install -U docker r: - oldrel diff --git a/NAMESPACE b/NAMESPACE index 827beec..bcfdc0a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ S3method(as.data.frame,harentries) S3method(as.data.frame,harentry) S3method(print,splash_debug) S3method(print,splash_json) +S3method(print,splashr) export("%>%") export(HARviewer) export(HARviewerOutput) @@ -77,11 +78,16 @@ export(splash_version) export(splash_wait) export(start_splash) export(stop_splash) +export(ua_android_samsung) +export(ua_apple_tv) +export(ua_chromecast) export(ua_ios_safari) +export(ua_kindle) export(ua_linux_chrome) export(ua_linux_firefox) export(ua_macos_chrome) export(ua_macos_safari) +export(ua_ps4) export(ua_splashr) export(ua_win10_chrome) export(ua_win10_firefox) diff --git a/NEWS.md b/NEWS.md index cd62508..905ceb7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ * Switch Docker orchestration to the `stevedore` package * Fixed minor check on as.data.frame functions +* Cleaned up splashr object printing +* Added Android, Kindle, Apple TV & Chromecast user agents and updated + other user agents +* Updated Travis config to not use old docker pkg components 0.5.0 diff --git a/R/splashr.r b/R/splashr.r index b17c37a..d50d290 100644 --- a/R/splashr.r +++ b/R/splashr.r @@ -2,6 +2,10 @@ splash_url <- function(splash_obj) { sprintf("http://%s:%s", splash_obj$host, sp #' Configure parameters for connecting to a Splash server #' +#' +#' @md +#' @note There is a quick "helper" object named `splash_local` which is preconfigured +#' with `localhost` as the host name. #' @param host host or IP address #' @param port port the server is running on (default is 8050) #' @param user,pass leave `NULL` if basic auth is not configured. Otherwise, @@ -11,7 +15,29 @@ splash_url <- function(splash_obj) { sprintf("http://%s:%s", splash_obj$host, sp #' sp <- splash() #' } splash <- function(host, port=8050L, user=NULL, pass=NULL) { - list(host=host, port=port, user=user, pass=pass) + obj <- list(host=host, port=port, user=user, pass=pass) + class(obj) <- c("splashr", "list") + obj +} + +#' Print for splashr +#' +#' @md +#' @param x a splashr object +#' @param ... unused +#' @keywords internal +#' @return x +#' @export +print.splashr <- function(x, ...) { + + cat( + "\n", sep="" + ) + + invisible(x) + } #' @rdname splash diff --git a/R/user-agents.R b/R/user-agents.R index 16a8d34..25c2e63 100644 --- a/R/user-agents.R +++ b/R/user-agents.R @@ -46,3 +46,23 @@ ua_linux_firefox <- "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/2010 #' @rdname splash_user_agent #' @export ua_ios_safari <- "Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1" + +#' @rdname splash_user_agent +#' @export +ua_android_samsung <- "Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36" + +#' @rdname splash_user_agent +#' @export +ua_kindle <- "Mozilla/5.0 (X11; U; Linux armv7l like Android; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/533.2+ Kindle/3.0+" + +#' @rdname splash_user_agent +#' @export +ua_ps4 <- "Mozilla/5.0 (PlayStation 4 3.11) AppleWebKit/537.73 (KHTML, like Gecko)" + +#' @rdname splash_user_agent +#' @export +ua_apple_tv <- "AppleTV6,2/11.1" + +#' @rdname splash_user_agent +#' @export +ua_chromecast <- "Mozilla/5.0 (CrKey armv7l 1.5.16041) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.0 Safari/537.36" diff --git a/man/print.splashr.Rd b/man/print.splashr.Rd new file mode 100644 index 0000000..c8b5960 --- /dev/null +++ b/man/print.splashr.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/splashr.R +\name{print.splashr} +\alias{print.splashr} +\title{Print for splashr} +\usage{ +\method{print}{splashr}(x, ...) +} +\arguments{ +\item{x}{a splashr object} + +\item{...}{unused} +} +\value{ +x +} +\description{ +Print for splashr +} +\keyword{internal} diff --git a/man/splash.Rd b/man/splash.Rd index fd47fb4..4150e97 100644 --- a/man/splash.Rd +++ b/man/splash.Rd @@ -5,7 +5,7 @@ \alias{splash} \alias{splash_local} \title{Configure parameters for connecting to a Splash server} -\format{An object of class \code{list} of length 4.} +\format{An object of class \code{splashr} (inherits from \code{list}) of length 4.} \usage{ splash(host, port = 8050L, user = NULL, pass = NULL) @@ -16,12 +16,16 @@ splash_local \item{port}{port the server is running on (default is 8050)} -\item{user, pass}{leave `NULL` if basic auth is not configured. Otherwise, +\item{user, pass}{leave \code{NULL} if basic auth is not configured. Otherwise, fill in what you need for basic authentication.} } \description{ Configure parameters for connecting to a Splash server } +\note{ +There is a quick "helper" object named \code{splash_local} which is preconfigured +with \code{localhost} as the host name. +} \examples{ \dontrun{ sp <- splash() diff --git a/man/splash_user_agent.Rd b/man/splash_user_agent.Rd index f73bdce..d0fdc63 100644 --- a/man/splash_user_agent.Rd +++ b/man/splash_user_agent.Rd @@ -15,6 +15,11 @@ \alias{ua_linux_chrome} \alias{ua_linux_firefox} \alias{ua_ios_safari} +\alias{ua_android_samsung} +\alias{ua_kindle} +\alias{ua_ps4} +\alias{ua_apple_tv} +\alias{ua_chromecast} \title{Overwrite the User-Agent header for all further requests.} \format{An object of class \code{character} of length 1.} \usage{ @@ -43,6 +48,16 @@ ua_linux_chrome ua_linux_firefox ua_ios_safari + +ua_android_samsung + +ua_kindle + +ua_ps4 + +ua_apple_tv + +ua_chromecast } \arguments{ \item{splash_obj}{splashr object} From 9a328819fa45d1c28b731749cc67998633cd2a2b Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sun, 13 Jan 2019 17:16:31 -0500 Subject: [PATCH 2/8] forgot 8050 in docker --- R/docker-splash.r | 2 +- tests/testthat/test-splash.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/docker-splash.r b/R/docker-splash.r index 184eb17..3c63f0f 100644 --- a/R/docker-splash.r +++ b/R/docker-splash.r @@ -42,7 +42,7 @@ start_splash <- function(tag="3.2", container_name = "splashr", remove=FALSE) { docker$container$run( image = sprintf("scrapinghub/splash:%s", tag), name = container_name, - ports = c("5023:5023", "8051:8051"), + ports = c("5023:5023", "8051:8051", "8050:8050"), detach = TRUE, rm = remove, tty = TRUE diff --git a/tests/testthat/test-splash.R b/tests/testthat/test-splash.R index 9f47bcd..7534d98 100644 --- a/tests/testthat/test-splash.R +++ b/tests/testthat/test-splash.R @@ -6,7 +6,7 @@ test_that("we can do something", { test_url <- "http://localhost:8050/" xpct <- function(x) { - spact <- splash_active() + spact <- splash_active(splash_local) expect_that(spact, equals(TRUE)) expect_that(length(splash_debug()), equals(7)) expect_that(length(splash_version()), equals(9)) @@ -17,7 +17,7 @@ test_that("we can do something", { expect_that(render_har(url = test_url), is_a("har")) } - spact <- splash_active() + spact <- splash_active(splash_local) if (spact) { xpct() From c4f5e2ffd32d100314ae48278a67816f547441bf Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Sun, 13 Jan 2019 20:19:12 -0500 Subject: [PATCH 3/8] travis --- .travis.yml | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a88a792..4658256 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: r cache: packages sudo: required dist: trusty +latex: false +fortran: false services: - docker @@ -9,11 +11,58 @@ services: env: global: - NOT_CRAN=true + - _R_CHECK_FORCE_SUGGESTS_=false + matrix: + include: + - dist: trusty + - dist: trusty + r_check_args: '--ignore-vignettes' + r_build_args: '--no-build-vignettes' + addons: + apt: + update: true + packages: + - libmagick++-dev + - librsvg2-dev + - libwebp-dev + - libpoppler-cpp-dev + - libtesseract-dev + - libleptonica-dev + - tesseract-ocr-eng + - r-cran-rgdal + - libfftw3-dev + - cargo + - PIP="pip" RETICULATE_PYTHON="/usr/bin/python" + - PYTHON=3 PIP="pip3" RETICULATE_PYTHON="/usr/bin/python3" + +addons: + apt: + update: true + sources: + - sourceline: 'ppa:opencpu/imagemagick' + packages: + - libmagick++-dev + - librsvg2-dev + - libwebp-dev + - libpoppler-cpp-dev + - libtesseract-dev + - libleptonica-dev + - tesseract-ocr-eng + - r-cran-rgdal + - libfftw3-dev + - cargo + +bioc_packages: + - EBImage before_install: - - docker pull scrapinghub/splash:3.2 - - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.2 + - docker pull scrapinghub/splash:3.0 + - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.0 - docker ps -a + - sudo apt-get -y install python${PYTHON}-pip python-dev python${PYTHON}-numpy + - sudo $PIP install -U setuptools + - sudo $PIP install -U docker + - (while true; do echo 'Ping? Pong!'; sleep 500; done) & r: - oldrel From 27cd1cab80596aedb5b8300a9953f0518a0c39c6 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Mon, 14 Jan 2019 04:52:50 -0500 Subject: [PATCH 4/8] more Travis --- .travis.yml | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4658256..9c8ef1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,12 +15,13 @@ env: matrix: include: - dist: trusty - - dist: trusty r_check_args: '--ignore-vignettes' r_build_args: '--no-build-vignettes' addons: apt: update: true + sources: + - sourceline: 'ppa:opencpu/imagemagick' packages: - libmagick++-dev - librsvg2-dev @@ -32,36 +33,13 @@ env: - r-cran-rgdal - libfftw3-dev - cargo - - PIP="pip" RETICULATE_PYTHON="/usr/bin/python" - - PYTHON=3 PIP="pip3" RETICULATE_PYTHON="/usr/bin/python3" - -addons: - apt: - update: true - sources: - - sourceline: 'ppa:opencpu/imagemagick' - packages: - - libmagick++-dev - - librsvg2-dev - - libwebp-dev - - libpoppler-cpp-dev - - libtesseract-dev - - libleptonica-dev - - tesseract-ocr-eng - - r-cran-rgdal - - libfftw3-dev - - cargo - -bioc_packages: - - EBImage + bioc_packages: + - EBImage before_install: - - docker pull scrapinghub/splash:3.0 - - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.0 + - docker pull scrapinghub/splash:3.2 + - docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 -d scrapinghub/splash:3.2 - docker ps -a - - sudo apt-get -y install python${PYTHON}-pip python-dev python${PYTHON}-numpy - - sudo $PIP install -U setuptools - - sudo $PIP install -U docker - (while true; do echo 'Ping? Pong!'; sleep 500; done) & r: From fffadd0fecc93bd40a6f52c476aeebece12b6075 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Mon, 14 Jan 2019 05:43:19 -0500 Subject: [PATCH 5/8] more Travis (magick) --- .travis.yml | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c8ef1a..75b4780 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,24 +17,27 @@ env: - dist: trusty r_check_args: '--ignore-vignettes' r_build_args: '--no-build-vignettes' - addons: - apt: - update: true - sources: - - sourceline: 'ppa:opencpu/imagemagick' - packages: - - libmagick++-dev - - librsvg2-dev - - libwebp-dev - - libpoppler-cpp-dev - - libtesseract-dev - - libleptonica-dev - - tesseract-ocr-eng - - r-cran-rgdal - - libfftw3-dev - - cargo - bioc_packages: - - EBImage + +addons: + apt: + update: true + sources: + - sourceline: 'ppa:opencpu/imagemagick' + - sourceline: 'ppa:ubuntugis/ppa' + packages: + - libmagick++-dev + - librsvg2-dev + - libwebp-dev + - libpoppler-cpp-dev + - libtesseract-dev + - libleptonica-dev + - tesseract-ocr-eng + - r-cran-rgdal + - libfftw3-dev + - cargo + +bioc_packages: + - EBImage before_install: - docker pull scrapinghub/splash:3.2 From 713450e2290617ca88c61272bd6eb73757493c3b Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Sun, 24 Feb 2019 20:40:29 -0500 Subject: [PATCH 6/8] CRAN test --- DESCRIPTION | 2 +- R/docker-splash.r | 13 ++++++++++--- man/as_har.Rd | 2 +- man/as_httr_req.Rd | 2 +- man/as_response.Rd | 2 +- man/execute_lua.Rd | 2 +- man/get_content_size.Rd | 2 +- man/get_content_type.Rd | 2 +- man/get_har_entry.Rd | 2 +- man/get_request_type.Rd | 2 +- man/get_request_url.Rd | 2 +- man/get_response_body.Rd | 2 +- man/har_entries.Rd | 2 +- man/har_entry_count.Rd | 2 +- man/install_splash.Rd | 4 ++-- man/json_fromb64.Rd | 2 +- man/killall_splash.Rd | 2 +- man/print.splashr.Rd | 2 +- man/render_har.Rd | 2 +- man/render_html.Rd | 2 +- man/render_jpeg.Rd | 2 +- man/render_json.Rd | 2 +- man/render_png.Rd | 2 +- man/splash.Rd | 2 +- man/splash_active.Rd | 2 +- man/splash_add_lua.Rd | 2 +- man/splash_click.Rd | 2 +- man/splash_debug.Rd | 2 +- man/splash_enable_javascript.Rd | 2 +- man/splash_focus.Rd | 2 +- man/splash_go.Rd | 2 +- man/splash_har.Rd | 2 +- man/splash_har_reset.Rd | 2 +- man/splash_history.Rd | 2 +- man/splash_html.Rd | 2 +- man/splash_images.Rd | 2 +- man/splash_perf_stats.Rd | 2 +- man/splash_plugins.Rd | 2 +- man/splash_png.Rd | 2 +- man/splash_press.Rd | 2 +- man/splash_private_mode.Rd | 2 +- man/splash_release.Rd | 2 +- man/splash_response_body.Rd | 2 +- man/splash_send_keys.Rd | 2 +- man/splash_send_text.Rd | 2 +- man/splash_user_agent.Rd | 2 +- man/splash_version.Rd | 2 +- man/splash_wait.Rd | 2 +- man/start_splash.Rd | 12 ++++++++++-- man/stop_splash.Rd | 2 +- 50 files changed, 69 insertions(+), 54 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a18104..dc39e1e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: splashr Type: Package Title: Tools to Work with the 'Splash' 'JavaScript' Rendering and Scraping Service Version: 0.6.0 -Date: 2019-01-13 +Date: 2019-02-24 Encoding: UTF-8 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), diff --git a/R/docker-splash.r b/R/docker-splash.r index 3c63f0f..60da759 100644 --- a/R/docker-splash.r +++ b/R/docker-splash.r @@ -9,7 +9,7 @@ #' splash_container <- start_splash() #' stop_splash(splash_container) #' } -install_splash <- function(tag="3.2") { +install_splash <- function(tag="latest") { docker <- stevedore::docker_client() res <- docker$image$pull("scrapinghub/splash", tag=tag, stream=stdout()) } @@ -19,6 +19,10 @@ install_splash <- function(tag="3.2") { #' If using this in an automation context, you should consider adding a #' `Sys.sleep(3)` (or higher) after starting the docker container. #' +#' This uses the `latest` image and passed the `--disable-browser-caches` +#' parameter. If you do not want to use the 3.2.x+ versions of `Splash` +#' you should use your own startup scripts vs this helper function. +#' #' @param tag Splash Docker image tag to start #' @note you need Docker running on your system and have pulled the container with #' [install_splash] for this to work. You should save the resultant @@ -27,6 +31,7 @@ install_splash <- function(tag="3.2") { #' @param container_name naem for the container. Defaults to "`splashr`". #' @param remove remove the Splash container instance after it's stopped? #' Defaults to `FALSE`. +#' @param ... passed on to Splash instance launch parameters #' @family splash_docker_helpers #' @return `stevedor` container object #' @export @@ -35,7 +40,7 @@ install_splash <- function(tag="3.2") { #' splash_container <- start_splash() #' stop_splash(splash_container) #' } -start_splash <- function(tag="3.2", container_name = "splashr", remove=FALSE) { +start_splash <- function(tag="latest", container_name = "splashr", remove=FALSE, ...) { docker <- stevedore::docker_client() @@ -45,7 +50,9 @@ start_splash <- function(tag="3.2", container_name = "splashr", remove=FALSE) { ports = c("5023:5023", "8051:8051", "8050:8050"), detach = TRUE, rm = remove, - tty = TRUE + tty = TRUE, + "--disable-browser-caches", + ... ) -> splash_inst invisible(splash_inst) diff --git a/man/as_har.Rd b/man/as_har.Rd index 46dc461..866d2bc 100644 --- a/man/as_har.Rd +++ b/man/as_har.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-har.R +% Please edit documentation in R/render-har.r \name{as_har} \alias{as_har} \title{Turn a generic Splash HAR response into a HAR object} diff --git a/man/as_httr_req.Rd b/man/as_httr_req.Rd index 1e8fb45..2b1a7a0 100644 --- a/man/as_httr_req.Rd +++ b/man/as_httr_req.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/as_req.R +% Please edit documentation in R/as_req.r \name{as_httr_req} \alias{as_httr_req} \title{Create an httr verb request function from an HAR request} diff --git a/man/as_response.Rd b/man/as_response.Rd index 322b086..37bf656 100644 --- a/man/as_response.Rd +++ b/man/as_response.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/as_request.R +% Please edit documentation in R/as_request.r \name{as_response} \alias{as_response} \title{Return a HAR entry response as an httr::response object} diff --git a/man/execute_lua.Rd b/man/execute_lua.Rd index 21d2972..1b50b40 100644 --- a/man/execute_lua.Rd +++ b/man/execute_lua.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/execute.R +% Please edit documentation in R/execute.r \name{execute_lua} \alias{execute_lua} \title{Execute a custom rendering script and return a result.} diff --git a/man/get_content_size.Rd b/man/get_content_size.Rd index a87931b..7a0c151 100644 --- a/man/get_content_size.Rd +++ b/man/get_content_size.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/content.R +% Please edit documentation in R/content.r \name{get_content_size} \alias{get_content_size} \alias{get_body_size} diff --git a/man/get_content_type.Rd b/man/get_content_type.Rd index 573eb21..0e3bbab 100644 --- a/man/get_content_type.Rd +++ b/man/get_content_type.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{get_content_type} \alias{get_content_type} \alias{is_content_type} diff --git a/man/get_har_entry.Rd b/man/get_har_entry.Rd index b1664c1..4311cdf 100644 --- a/man/get_har_entry.Rd +++ b/man/get_har_entry.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{get_har_entry} \alias{get_har_entry} \title{Retrieve an entry by index from a HAR object} diff --git a/man/get_request_type.Rd b/man/get_request_type.Rd index 556a347..ade7b01 100644 --- a/man/get_request_type.Rd +++ b/man/get_request_type.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{get_request_type} \alias{get_request_type} \alias{is_get} diff --git a/man/get_request_url.Rd b/man/get_request_url.Rd index 5d1a0a1..ce17ffe 100644 --- a/man/get_request_url.Rd +++ b/man/get_request_url.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{get_request_url} \alias{get_request_url} \title{Retrieve request URL} diff --git a/man/get_response_body.Rd b/man/get_response_body.Rd index 859217c..2542102 100644 --- a/man/get_response_body.Rd +++ b/man/get_response_body.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{get_response_body} \alias{get_response_body} \title{Retrieve the body content of a HAR entry} diff --git a/man/har_entries.Rd b/man/har_entries.Rd index bac527b..b5969f9 100644 --- a/man/har_entries.Rd +++ b/man/har_entries.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{har_entries} \alias{har_entries} \title{Retrieve just the HAR entries from a splashr request} diff --git a/man/har_entry_count.Rd b/man/har_entry_count.Rd index af46d44..1ab8ef1 100644 --- a/man/har_entry_count.Rd +++ b/man/har_entry_count.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R +% Please edit documentation in R/helpers.r \name{har_entry_count} \alias{har_entry_count} \title{Retrieves number of HAR entries in a response} diff --git a/man/install_splash.Rd b/man/install_splash.Rd index f865f1f..2422459 100644 --- a/man/install_splash.Rd +++ b/man/install_splash.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/docker-splash.R +% Please edit documentation in R/docker-splash.r \name{install_splash} \alias{install_splash} \title{Retrieve the Docker image for Splash} \usage{ -install_splash(tag = "3.2") +install_splash(tag = "latest") } \arguments{ \item{tag}{Splash Docker image tag to install} diff --git a/man/json_fromb64.Rd b/man/json_fromb64.Rd index ae280bd..dbc2a91 100644 --- a/man/json_fromb64.Rd +++ b/man/json_fromb64.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/utils.r \name{json_fromb64} \alias{json_fromb64} \title{Convert a Base64 encoded string into an R object} diff --git a/man/killall_splash.Rd b/man/killall_splash.Rd index ee89a51..832d5db 100644 --- a/man/killall_splash.Rd +++ b/man/killall_splash.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/docker-splash.R +% Please edit documentation in R/docker-splash.r \name{killall_splash} \alias{killall_splash} \title{Prune all dead and running Splash Docker containers} diff --git a/man/print.splashr.Rd b/man/print.splashr.Rd index c8b5960..a7ffa6a 100644 --- a/man/print.splashr.Rd +++ b/man/print.splashr.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{print.splashr} \alias{print.splashr} \title{Print for splashr} diff --git a/man/render_har.Rd b/man/render_har.Rd index 93b3b61..00d52b0 100644 --- a/man/render_har.Rd +++ b/man/render_har.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-har.R +% Please edit documentation in R/render-har.r \name{render_har} \alias{render_har} \title{Return information about Splash interaction with a website in HAR format.} diff --git a/man/render_html.Rd b/man/render_html.Rd index 8012666..7f4eebc 100644 --- a/man/render_html.Rd +++ b/man/render_html.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-html.R +% Please edit documentation in R/render-html.r \name{render_html} \alias{render_html} \title{Return the HTML of the javascript-rendered page.} diff --git a/man/render_jpeg.Rd b/man/render_jpeg.Rd index 6924dff..edd9d25 100644 --- a/man/render_jpeg.Rd +++ b/man/render_jpeg.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-jpg.R +% Please edit documentation in R/render-jpg.r \name{render_jpeg} \alias{render_jpeg} \title{Return a image (in JPEG format) of the javascript-rendered page.} diff --git a/man/render_json.Rd b/man/render_json.Rd index 26c02fb..03d961d 100644 --- a/man/render_json.Rd +++ b/man/render_json.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-json.R +% Please edit documentation in R/render-json.r \name{render_json} \alias{render_json} \title{Return a json-encoded dictionary with information about javascript-rendered webpage.} diff --git a/man/render_png.Rd b/man/render_png.Rd index ec746f6..bd02d35 100644 --- a/man/render_png.Rd +++ b/man/render_png.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/render-png.R +% Please edit documentation in R/render-png.r \name{render_png} \alias{render_png} \title{Return an image (in PNG format) of the javascript-rendered page.} diff --git a/man/splash.Rd b/man/splash.Rd index 4150e97..fd0a77d 100644 --- a/man/splash.Rd +++ b/man/splash.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \docType{data} \name{splash} \alias{splash} diff --git a/man/splash_active.Rd b/man/splash_active.Rd index 5c64313..95e7ab7 100644 --- a/man/splash_active.Rd +++ b/man/splash_active.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{splash_active} \alias{splash_active} \title{Test if a Splash server is up} diff --git a/man/splash_add_lua.Rd b/man/splash_add_lua.Rd index ac57c03..f8d9c7d 100644 --- a/man/splash_add_lua.Rd +++ b/man/splash_add_lua.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_add_lua} \alias{splash_add_lua} \title{Add raw lua code into DSL call chain} diff --git a/man/splash_click.Rd b/man/splash_click.Rd index 2ee197d..c1eed58 100644 --- a/man/splash_click.Rd +++ b/man/splash_click.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_click} \alias{splash_click} \title{Trigger mouse click event in web page.} diff --git a/man/splash_debug.Rd b/man/splash_debug.Rd index 5a9ed78..1e55fde 100644 --- a/man/splash_debug.Rd +++ b/man/splash_debug.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{splash_debug} \alias{splash_debug} \alias{print.splash_debug} diff --git a/man/splash_enable_javascript.Rd b/man/splash_enable_javascript.Rd index d359c7c..4c54bd3 100644 --- a/man/splash_enable_javascript.Rd +++ b/man/splash_enable_javascript.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_enable_javascript} \alias{splash_enable_javascript} \title{Enable or disable execution of JavaSript code embedded in the page.} diff --git a/man/splash_focus.Rd b/man/splash_focus.Rd index b31891c..49ad75d 100644 --- a/man/splash_focus.Rd +++ b/man/splash_focus.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_focus} \alias{splash_focus} \title{Focus on a document element provided by a CSS selector} diff --git a/man/splash_go.Rd b/man/splash_go.Rd index f0c7698..ec52ee5 100644 --- a/man/splash_go.Rd +++ b/man/splash_go.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_go} \alias{splash_go} \title{Go to an URL.} diff --git a/man/splash_har.Rd b/man/splash_har.Rd index b771ab3..7b82ec3 100644 --- a/man/splash_har.Rd +++ b/man/splash_har.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_har} \alias{splash_har} \title{Return information about Splash interaction with a website in HAR format.} diff --git a/man/splash_har_reset.Rd b/man/splash_har_reset.Rd index 1ed9eaf..f98551c 100644 --- a/man/splash_har_reset.Rd +++ b/man/splash_har_reset.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_har_reset} \alias{splash_har_reset} \title{Drops all internally stored HAR records.} diff --git a/man/splash_history.Rd b/man/splash_history.Rd index d328c52..7e87566 100644 --- a/man/splash_history.Rd +++ b/man/splash_history.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{splash_history} \alias{splash_history} \title{Get information about requests/responses for the pages loaded} diff --git a/man/splash_html.Rd b/man/splash_html.Rd index cbe9427..9888cb0 100644 --- a/man/splash_html.Rd +++ b/man/splash_html.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_html} \alias{splash_html} \title{Return a HTML snapshot of a current page.} diff --git a/man/splash_images.Rd b/man/splash_images.Rd index 1268b30..7a15144 100644 --- a/man/splash_images.Rd +++ b/man/splash_images.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_images} \alias{splash_images} \title{Enable/disable images} diff --git a/man/splash_perf_stats.Rd b/man/splash_perf_stats.Rd index 1067c17..b43213a 100644 --- a/man/splash_perf_stats.Rd +++ b/man/splash_perf_stats.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{splash_perf_stats} \alias{splash_perf_stats} \title{Get Splash performance-related statistics} diff --git a/man/splash_plugins.Rd b/man/splash_plugins.Rd index f7df3d0..13f814f 100644 --- a/man/splash_plugins.Rd +++ b/man/splash_plugins.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_plugins} \alias{splash_plugins} \title{Enable or disable browser plugins (e.g. Flash).} diff --git a/man/splash_png.Rd b/man/splash_png.Rd index a20cfdb..5a50a92 100644 --- a/man/splash_png.Rd +++ b/man/splash_png.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_png} \alias{splash_png} \title{Return a screenshot of a current page in PNG format.} diff --git a/man/splash_press.Rd b/man/splash_press.Rd index 3b506d8..ce4f99d 100644 --- a/man/splash_press.Rd +++ b/man/splash_press.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_press} \alias{splash_press} \title{Trigger mouse press event in web page.} diff --git a/man/splash_private_mode.Rd b/man/splash_private_mode.Rd index 36a0c8b..6e33cc8 100644 --- a/man/splash_private_mode.Rd +++ b/man/splash_private_mode.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_private_mode} \alias{splash_private_mode} \title{Enable or disable execution of JavaSript code embedded in the page.} diff --git a/man/splash_release.Rd b/man/splash_release.Rd index 39a8651..50d38f0 100644 --- a/man/splash_release.Rd +++ b/man/splash_release.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_release} \alias{splash_release} \title{Trigger mouse release event in web page.} diff --git a/man/splash_response_body.Rd b/man/splash_response_body.Rd index 9f2753d..300a6bc 100644 --- a/man/splash_response_body.Rd +++ b/man/splash_response_body.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_response_body} \alias{splash_response_body} \title{Enable or disable response content tracking.} diff --git a/man/splash_send_keys.Rd b/man/splash_send_keys.Rd index b1ceda9..9e0e6e9 100644 --- a/man/splash_send_keys.Rd +++ b/man/splash_send_keys.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_send_keys} \alias{splash_send_keys} \title{Send keyboard events to page context.} diff --git a/man/splash_send_text.Rd b/man/splash_send_text.Rd index 412ad95..b912c83 100644 --- a/man/splash_send_text.Rd +++ b/man/splash_send_text.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_send_text} \alias{splash_send_text} \title{Send text as input to page context, literally, character by character.} diff --git a/man/splash_user_agent.Rd b/man/splash_user_agent.Rd index d0fdc63..69f5965 100644 --- a/man/splash_user_agent.Rd +++ b/man/splash_user_agent.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R, R/user-agents.R +% Please edit documentation in R/dsl.r, R/user-agents.R \docType{data} \name{splash_user_agent} \alias{splash_user_agent} diff --git a/man/splash_version.Rd b/man/splash_version.Rd index 13960cb..509b0d3 100644 --- a/man/splash_version.Rd +++ b/man/splash_version.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splashr.R +% Please edit documentation in R/splashr.r \name{splash_version} \alias{splash_version} \title{Get Splash version information} diff --git a/man/splash_wait.Rd b/man/splash_wait.Rd index 6fa1180..53df349 100644 --- a/man/splash_wait.Rd +++ b/man/splash_wait.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dsl.R +% Please edit documentation in R/dsl.r \name{splash_wait} \alias{splash_wait} \title{Wait for a period time} diff --git a/man/start_splash.Rd b/man/start_splash.Rd index e8ae152..32559d5 100644 --- a/man/start_splash.Rd +++ b/man/start_splash.Rd @@ -1,10 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/docker-splash.R +% Please edit documentation in R/docker-splash.r \name{start_splash} \alias{start_splash} \title{Start a Splash server Docker container} \usage{ -start_splash(tag = "3.2", container_name = "splashr", remove = FALSE) +start_splash(tag = "latest", container_name = "splashr", + remove = FALSE, ...) } \arguments{ \item{tag}{Splash Docker image tag to start} @@ -13,6 +14,8 @@ start_splash(tag = "3.2", container_name = "splashr", remove = FALSE) \item{remove}{remove the Splash container instance after it's stopped? Defaults to `FALSE`.} + +\item{...}{passed on to Splash instance launch parameters} } \value{ `stevedor` container object @@ -21,6 +24,11 @@ Defaults to `FALSE`.} If using this in an automation context, you should consider adding a `Sys.sleep(3)` (or higher) after starting the docker container. } +\details{ +This uses the `latest` image and passed the `--disable-browser-caches` +parameter. If you do not want to use the 3.2.x+ versions of `Splash` +you should use your own startup scripts vs this helper function. +} \note{ you need Docker running on your system and have pulled the container with [install_splash] for this to work. You should save the resultant diff --git a/man/stop_splash.Rd b/man/stop_splash.Rd index 30d1403..b867fe9 100644 --- a/man/stop_splash.Rd +++ b/man/stop_splash.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/docker-splash.R +% Please edit documentation in R/docker-splash.r \name{stop_splash} \alias{stop_splash} \title{Stop a running a Splash server Docker container} From 2f6e4110ee1e1e4921089067e0d336150c8fd1b8 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Sun, 24 Feb 2019 20:41:43 -0500 Subject: [PATCH 7/8] license --- .Rbuildignore | 1 + DESCRIPTION | 2 +- LICENSE | 2 ++ LICENSE.md | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 LICENSE.md diff --git a/.Rbuildignore b/.Rbuildignore index 1038c36..b68b069 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ +^LICENSE\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ ^\.travis\.yml$ diff --git a/DESCRIPTION b/DESCRIPTION index dc39e1e..acf2465 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Description: 'Splash' is a 'JavaScript' page context; getting detailed rendering info in 'HAR' format. URL: http://gitlab.com/hrbrmstr/splashr BugReports: https://gitlab.com/hrbrmstr/splashr/issues -License: AGPL +License: MIT + file LICENSE Suggests: testthat, tibble, diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b6a10f1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2019 +COPYRIGHT HOLDER: Bob Rudis diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c36552c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2019 Bob Rudis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 34c15bb3f04a5ced863e250d129d6f3db2595e4f Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Tue, 26 Feb 2019 05:32:29 -0500 Subject: [PATCH 8/8] pre-CRAN flight check --- R/docker-splash.r | 55 +++++++++++++++++++++++-------- R/utils-safely.R | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ man/install_splash.Rd | 3 ++ man/start_splash.Rd | 2 +- 4 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 R/utils-safely.R diff --git a/R/docker-splash.r b/R/docker-splash.r index 60da759..ab90f6e 100644 --- a/R/docker-splash.r +++ b/R/docker-splash.r @@ -2,6 +2,7 @@ #' #' @md #' @param tag Splash Docker image tag to install +#' @return a `docker_image` object or `NULL` if an error occurred. #' @export #' @family splash_docker_helpers #' @examples \dontrun{ @@ -10,8 +11,22 @@ #' stop_splash(splash_container) #' } install_splash <- function(tag="latest") { + docker <- stevedore::docker_client() - res <- docker$image$pull("scrapinghub/splash", tag=tag, stream=stdout()) + + tryCatch( + docker$image$pull("scrapinghub/splash", tag=tag, stream=stdout()), + error = function(e) { + message("Error pulling image from DockerHub.\n", e) + return(NULL) + }, + interrupt = function(e) { + stop("Terminated by user", call. = FALSE) + } + ) -> res + + invisible(res) + } #' Start a Splash server Docker container @@ -33,7 +48,7 @@ install_splash <- function(tag="latest") { #' Defaults to `FALSE`. #' @param ... passed on to Splash instance launch parameters #' @family splash_docker_helpers -#' @return `stevedor` container object +#' @return `stevedore` container object #' @export #' @examples \dontrun{ #' install_splash() @@ -44,15 +59,24 @@ start_splash <- function(tag="latest", container_name = "splashr", remove=FALSE, docker <- stevedore::docker_client() - docker$container$run( - image = sprintf("scrapinghub/splash:%s", tag), - name = container_name, - ports = c("5023:5023", "8051:8051", "8050:8050"), - detach = TRUE, - rm = remove, - tty = TRUE, - "--disable-browser-caches", - ... + tryCatch( + docker$container$run( + image = sprintf("scrapinghub/splash:%s", tag), + name = container_name, + ports = c("5023:5023", "8051:8051", "8050:8050"), + detach = TRUE, + rm = remove, + tty = TRUE, + "--disable-browser-caches", + ... + ), + error = function(e) { + message("Error pulling image from DockerHub.") + return(NULL) + }, + interrupt = function(e) { + stop("Terminated by user", call. = FALSE) + } ) -> splash_inst invisible(splash_inst) @@ -73,8 +97,10 @@ start_splash <- function(tag="latest", container_name = "splashr", remove=FALSE, #' stop_splash(splash_container) #' } stop_splash <- function(splash_container) { - splash_container$stop() - splash_container$remove() + if (inherits(splash_container, "stevedore_object")) { + splash_container$stop() + splash_container$remove() + } invisible(NULL) } @@ -90,7 +116,9 @@ stop_splash <- function(splash_container) { killall_splash <- function() { docker <- stevedore::docker_client() + x <- docker$container$list(all=TRUE) + for (i in 1:nrow(x)) { if (grepl("bin/splash", x$command[i])) { message(sprintf("Pruning: %s...", x$id[i])) @@ -101,6 +129,7 @@ killall_splash <- function() { } } } + } diff --git a/R/utils-safely.R b/R/utils-safely.R new file mode 100644 index 0000000..8e7f90d --- /dev/null +++ b/R/utils-safely.R @@ -0,0 +1,90 @@ +# Less cool counterparts to purrr's side-effect capture-rs +# +# Most of the helper functions are 100% from output.R in purrr repo +# +# @param quiet Hide errors (`TRUE`, the default), or display them +# as they occur? +# @param otherwise Default value to use when an error occurs. +# +# @return `safely`: wrapped function instead returns a list with +# components `result` and `error`. One value is always `NULL`. +# +# `quietly`: wrapped function instead returns a list with components +# `result`, `output`, `messages` and `warnings`. +# +# `possibly`: wrapped function uses a default value (`otherwise`) +# whenever an error occurs. +safely <- function(.f, otherwise = NULL, quiet = TRUE) { + function(...) capture_error(.f(...), otherwise, quiet) +} + +quietly <- function(.f) { + function(...) capture_output(.f(...)) +} + +possibly <- function(.f, otherwise, quiet = TRUE) { + force(otherwise) + function(...) { + tryCatch(.f(...), + error = function(e) { + if (!quiet) + message("Error: ", e$message) + otherwise + }, + interrupt = function(e) { + stop("Terminated by user", call. = FALSE) + } + ) + } +} + +capture_error <- function(code, otherwise = NULL, quiet = TRUE) { + tryCatch( + list(result = code, error = NULL), + error = function(e) { + if (!quiet) + message("Error: ", e$message) + + list(result = otherwise, error = e) + }, + interrupt = function(e) { + stop("Terminated by user", call. = FALSE) + } + ) +} + +capture_output <- function(code) { + warnings <- character() + wHandler <- function(w) { + warnings <<- c(warnings, w$message) + invokeRestart("muffleWarning") + } + + messages <- character() + mHandler <- function(m) { + messages <<- c(messages, m$message) + invokeRestart("muffleMessage") + } + + temp <- file() + sink(temp) + on.exit({ + sink() + close(temp) + }) + + result <- withCallingHandlers( + code, + warning = wHandler, + message = mHandler + ) + + output <- paste0(readLines(temp, warn = FALSE), collapse = "\n") + + list( + result = result, + output = output, + warnings = warnings, + messages = messages + ) +} diff --git a/man/install_splash.Rd b/man/install_splash.Rd index 2422459..df14a72 100644 --- a/man/install_splash.Rd +++ b/man/install_splash.Rd @@ -9,6 +9,9 @@ install_splash(tag = "latest") \arguments{ \item{tag}{Splash Docker image tag to install} } +\value{ +a \code{docker_image} object or \code{NULL} if an error occurred. +} \description{ Retrieve the Docker image for Splash } diff --git a/man/start_splash.Rd b/man/start_splash.Rd index 32559d5..995645a 100644 --- a/man/start_splash.Rd +++ b/man/start_splash.Rd @@ -18,7 +18,7 @@ Defaults to `FALSE`.} \item{...}{passed on to Splash instance launch parameters} } \value{ -`stevedor` container object +`stevedore` container object } \description{ If using this in an automation context, you should consider adding a