Browse Source

add func get_env, set_env

add onAttach for env
pull/2/head
mrchypark 7 years ago
parent
commit
a5484d933c
  1. 2
      NAMESPACE
  2. 22
      R/env.R
  3. 15
      R/onAttach.R
  4. 7
      R/version.r
  5. 5
      README.Rmd
  6. 3
      man/chrome_version.Rd
  7. 17
      man/get_env.Rd
  8. 20
      man/set_env.Rd

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)
}

15
R/onAttach.R

@ -0,0 +1,15 @@
.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
}
}

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