Browse Source

Merge pull request #2 from mrchypark/master

im trying to set auto env
master
boB Rudis 7 years ago
committed by GitHub
parent
commit
175759fbdf
  1. 1
      DESCRIPTION
  2. 2
      NAMESPACE
  3. 22
      R/env.R
  4. 16
      R/onAttach.R
  5. 7
      R/version.r
  6. 5
      README.Rmd
  7. 3
      man/chrome_version.Rd
  8. 17
      man/get_env.Rd
  9. 20
      man/set_env.Rd

1
DESCRIPTION

@ -5,6 +5,7 @@ Version: 0.1.0
Date: 2017-05-02
Author: Bob Rudis (bob@rud.is)
Maintainer: Bob Rudis <bob@rud.is>
Contributor: Chanyub Park <mrchypark@gmail.com>
Description: The 'Chrome' browser <https://www.google.com/chrome/> has a headless mode
which can be instrumented programmatically. Tools are provided to perform headless
'Chrome' instrumentation on the command-line and will eventually provide support

2
NAMESPACE

@ -4,5 +4,7 @@ export(chrome_dump_pdf)
export(chrome_read_html)
export(chrome_shot)
export(chrome_version)
export(get_env)
export(set_env)
import(magick)
import(xml2)

22
R/env.R

@ -0,0 +1,22 @@
#' get an envrionment variable `HEADLESS_CHROME`
#'
#' @md
#' @note This only return an envrionment variable `HEADLESS_CHROME`.
#' @export
#' @examples
#' get_env()
get_env <- function() {
Sys.getenv("HEADLESS_CHROME")
}
#' set an envrionment variable `HEADLESS_CHROME`
#'
#' @md
#' @note This only grabs the `<body>` `innerHTML` contents
#' @param env path of chrome execute file for an envrionment variable `HEADLESS_CHROME`
#' @export
#' @examples
#' set_env("C:/Program Files/Google/Chrome/Application/chrome.exe")
set_env <- function(env=Sys.getenv("HEADLESS_CHROME")) {
Sys.setenv(HEADLESS_CHROME=env)
}

16
R/onAttach.R

@ -0,0 +1,16 @@
.onAttach <- function(libname, pkgname) {
if (interactive()) {
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")
} else {
Sys.setenv(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")
}
# check other os
chrome_bin <- Sys.getenv("HEADLESS_CHROME")
}
}

7
R/version.r

@ -1,4 +1,9 @@
#' Get Chrome version
#'
#' @md
#' @export
chrome_version <- function(x) { system2(chrome_bin, "--version") }
#' @examples
#' chrome_version()
chrome_version <- function() {
system2(chrome_bin, "--version")
}

5
README.Rmd

@ -13,9 +13,10 @@ for the 'DevTools' instrumentation 'API' or the forthcoming 'phantomjs'-like hig
### IMPORTANT
This pkg will eventually do much under the covers to find the location of the Chrome binary
on all operating systems. For now, you'll need to set an envrionment variable `HEADLESS_CHROME` to one of these two values:
on all operating systems. For now, you'll need to set an envrionment variable `HEADLESS_CHROME` to one of these values:
- Windows: `C:\Program Files\Google\Chrome\Application\chrome.exe`
- Windows(32bit): `C:/Program Files/Google/Chrome/Application/chrome.exe`
- Windows(64bit): `C:/Program Files (x86)/Google/Chrome/Application/chrome.exe`
- macOS: `/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome`
Linux folks will know where their binary is (many of you use non-default locations for things).

3
man/chrome_version.Rd

@ -9,3 +9,6 @@ chrome_version(x)
\description{
Get Chrome version
}
\examples{
chrome_version()
}

17
man/get_env.Rd

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{get_env}
\alias{get_env}
\title{get an envrionment variable \code{HEADLESS_CHROME}}
\usage{
get_env()
}
\description{
get an envrionment variable \code{HEADLESS_CHROME}
}
\note{
This only return an envrionment variable \code{HEADLESS_CHROME}.
}
\examples{
get_env()
}

20
man/set_env.Rd

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{set_env}
\alias{set_env}
\title{set an envrionment variable \code{HEADLESS_CHROME}}
\usage{
set_env(env = Sys.getenv("HEADLESS_CHROME"))
}
\arguments{
\item{env}{path of chrome execute file for an envrionment variable \code{HEADLESS_CHROME}}
}
\description{
set an envrionment variable \code{HEADLESS_CHROME}
}
\note{
This only grabs the \code{<body>} \code{innerHTML} contents
}
\examples{
set_env("C:/Program Files/Google/Chrome/Application/chrome.exe")
}
Loading…
Cancel
Save