boB Rudis
8 years ago
commit
a5f3b2c269
19 changed files with 6486 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||
^.*\.Rproj$ |
|||
^\.Rproj\.user$ |
|||
^\.travis\.yml$ |
|||
^README\.Rmd$ |
|||
^README\.*html$ |
|||
^NOTES\.*Rmd$ |
|||
^NOTES\.*html$ |
@ -0,0 +1,7 @@ |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Rproj |
|||
src/*.o |
|||
src/*.so |
|||
src/*.dll |
@ -0,0 +1,17 @@ |
|||
language: r |
|||
warnings_are_errors: true |
|||
sudo: required |
|||
|
|||
apt_packages: |
|||
- binutils |
|||
- libproj-dev |
|||
- gdal-bin |
|||
|
|||
env: |
|||
global: |
|||
- CRAN: http://cran.rstudio.com |
|||
|
|||
notifications: |
|||
email: |
|||
on_success: change |
|||
on_failure: change |
@ -0,0 +1,25 @@ |
|||
Package: uaparserjs |
|||
Type: Package |
|||
Title: Parse Browser 'User-Agent' Strings into Data Frames |
|||
Version: 0.1.0 |
|||
Date: 2016-08-04 |
|||
Author: Bob Rudis (@hrbrmstr) |
|||
Maintainer: Bob Rudis <bob@rudis.net> |
|||
Description: Despite there being a section in RFC 7231 |
|||
<https://tools.ietf.org/html/rfc7231#section-5.5.3> defining a suggested |
|||
structure for 'User-Agent' headers this data is notoriously difficult |
|||
to parse consistently. A function is provided that will take in user agent |
|||
strings and return structured R objects. This is a 'V8'-backed package |
|||
based on the 'ua-parser' project <https://github.com/ua-parser>. |
|||
URL: http://github.com/hrbrmstr/uaparserjs |
|||
BugReports: https://github.com/hrbrmstr/uaparserjs/issues |
|||
License: AGPL |
|||
Suggests: |
|||
testthat |
|||
Depends: |
|||
R (>= 3.0.0) |
|||
Imports: |
|||
purrr, |
|||
dplyr, |
|||
V8 |
|||
RoxygenNote: 5.0.1 |
@ -0,0 +1,7 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
export(ua_parse) |
|||
import(V8) |
|||
importFrom(dplyr,as_data_frame) |
|||
importFrom(purrr,map) |
|||
importFrom(purrr,map_df) |
@ -0,0 +1,2 @@ |
|||
0.1.0 |
|||
* Initial release |
@ -0,0 +1,23 @@ |
|||
#' Parse a vector of user agents into a data frame |
|||
#' |
|||
#' Takes in a character vector of user agent strings and returns a \code{tibble} |
|||
#' of parsed user agents. |
|||
#' |
|||
#' @param user_agents a character vector of user agents |
|||
#' @export |
|||
#' @return a \code{tibble} with columns for user agent family, major & minor versions |
|||
#' plus patch level along with os family and major & minor versions plus |
|||
#' device brand and model. |
|||
#' @references \url{http://www.uaparser.org/} |
|||
#' @note The regex YAML import date: 2016-08-04 |
|||
#' @examples |
|||
#' ua_parse(paste0("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, ", |
|||
#' "like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 ", |
|||
#' "Chrome/15.0.874.106 Safari/535.2", collapse="")) |
|||
ua_parse <- function(user_agents) { |
|||
|
|||
purrr::map_df(user_agents, function(x) { |
|||
dplyr::as_data_frame(as.list(unlist(.pkgenv$ctx$call("parser.parse", x)))) |
|||
}) |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
#' Parse Browser User Agent Strings into Data Frames |
|||
#' |
|||
#' @name uaparserjs |
|||
#' @docType package |
|||
#' @author Bob Rudis (@@hrbrmstr) |
|||
#' @importFrom purrr map map_df |
|||
#' @import V8 |
|||
#' @importFrom dplyr as_data_frame |
|||
NULL |
@ -0,0 +1,12 @@ |
|||
|
|||
.pkgenv <- new.env(parent=emptyenv()) |
|||
|
|||
.onAttach <- function(...) { |
|||
|
|||
ctx <- v8() |
|||
ctx$source(system.file("js/bundle.js", package="uaparserjs")) |
|||
ctx$eval(JS('var parser = uap(regexes)')) |
|||
|
|||
assign("ctx", ctx, envir=.pkgenv) |
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
--- |
|||
output: rmarkdown::github_document |
|||
--- |
|||
|
|||
`uaparserjs` : Parse Browser 'User-Agent' Strings into Data Frames |
|||
|
|||
Despite there being a section in RFC 7231 <https://tools.ietf.org/html/rfc7231#section-5.5.3> defining a suggested structure for `User-Agent` headers this data is notoriously difficult to parse consistently. A function is provided that will take in user agent strings and return structured R objects. This is a V8-backed package based on the `ua-parser` project <https://github.com/ua-parser>. |
|||
|
|||
NOTE: there is a [C++-backed R package](https://github.com/ua-parser/uap-r) but it has [issues](https://github.com/ua-parser/uap-r/issues) compiling on a few platforms and is dependent upon Boost regex. This version is definitely slower but it works on all platforms. |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `ua_parse` : Parse a vector of user agents into a data frame |
|||
|
|||
### Installation |
|||
|
|||
```{r eval=FALSE} |
|||
devtools::install_github("hrbrmstr/uaparserjs") |
|||
``` |
|||
|
|||
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} |
|||
options(width=120) |
|||
``` |
|||
|
|||
### Usage |
|||
|
|||
```{r} |
|||
library(uaparserjs) |
|||
|
|||
# current verison |
|||
packageVersion("uaparserjs") |
|||
|
|||
dplyr::glimpse(ua_parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2")) |
|||
|
|||
dplyr::glimpse(ua_parse(readLines("tests/agents.txt"))) |
|||
|
|||
``` |
|||
|
|||
### Test Results |
|||
|
|||
```{r} |
|||
library(uaparserjs) |
|||
library(testthat) |
|||
|
|||
date() |
|||
|
|||
test_dir("tests/") |
|||
``` |
|||
|
@ -0,0 +1,83 @@ |
|||
|
|||
`uaparserjs` : Parse Browser 'User-Agent' Strings into Data Frames |
|||
|
|||
Despite there being a section in RFC 7231 <https://tools.ietf.org/html/rfc7231#section-5.5.3> defining a suggested structure for `User-Agent` headers this data is notoriously difficult to parse consistently. A function is provided that will take in user agent strings and return structured R objects. This is a V8-backed package based on the `ua-parser` project <https://github.com/ua-parser>. |
|||
|
|||
NOTE: there is a [C++-backed R package](https://github.com/ua-parser/uap-r) but it has [issues](https://github.com/ua-parser/uap-r/issues) compiling on a few platforms and is dependent upon Boost regex. This version is definitely slower but it works on all platforms. |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `ua_parse` : Parse a vector of user agents into a data frame |
|||
|
|||
### Installation |
|||
|
|||
``` r |
|||
devtools::install_github("hrbrmstr/uaparserjs") |
|||
``` |
|||
|
|||
### Usage |
|||
|
|||
``` r |
|||
library(uaparserjs) |
|||
|
|||
# current verison |
|||
packageVersion("uaparserjs") |
|||
``` |
|||
|
|||
## [1] '0.1.0' |
|||
|
|||
``` r |
|||
dplyr::glimpse(ua_parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2")) |
|||
``` |
|||
|
|||
## Observations: 1 |
|||
## Variables: 9 |
|||
## $ userAgent <chr> "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/... |
|||
## $ ua.family <chr> "Chromium" |
|||
## $ ua.major <chr> "15" |
|||
## $ ua.minor <chr> "0" |
|||
## $ ua.patch <chr> "874" |
|||
## $ os.family <chr> "Ubuntu" |
|||
## $ os.major <chr> "11" |
|||
## $ os.minor <chr> "10" |
|||
## $ device.family <chr> "Other" |
|||
|
|||
``` r |
|||
dplyr::glimpse(ua_parse(readLines("tests/agents.txt"))) |
|||
``` |
|||
|
|||
## Observations: 1,091 |
|||
## Variables: 13 |
|||
## $ userAgent <chr> "Mozilla/5.0 (Windows; U; en-US) AppleWebKit/531.9 (KHTML, like Gecko) AdobeAIR/2.5.1", "Mozi... |
|||
## $ ua.family <chr> "AdobeAIR", "Amazon Silk", "Amazon Silk", "Amazon Silk", "Amazon Silk", "Amazon Silk", "Andro... |
|||
## $ ua.major <chr> "2", "1", "2", "2", "2", "3", "2", "2", "2", "2", "3", "4", "4", "4", "4", "1", "1", "6", "7"... |
|||
## $ ua.minor <chr> "5", "1", "0", "1", "2", "25", "2", "3", "3", "3", "0", "0", "0", "0", "0", NA, NA, "13", "6"... |
|||
## $ ua.patch <chr> "1", "0-80", NA, NA, NA, NA, "2", "3", "4", "5", "1", "3", "3", "3", "4", NA, NA, "13719", "2... |
|||
## $ os.family <chr> "Windows", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Andr... |
|||
## $ device.family <chr> "Other", "Kindle", "Kindle Fire HD", "Kindle Fire", "Kindle Fire HD", "Kindle Fire HD", "HTC ... |
|||
## $ device.brand <chr> NA, "Amazon", "Amazon", "Amazon", "Amazon", "Amazon", "HTC", "HTC", "Amazon", "Tecno", "Samsu... |
|||
## $ device.model <chr> NA, "Kindle", "Kindle Fire HD 7\"", "Kindle Fire", "Kindle Fire HD 7\"", "Kindle Fire HD 7\""... |
|||
## $ os.major <chr> NA, NA, NA, NA, NA, "4", "2", "2", "2", "2", "3", "4", "4", "4", "4", NA, NA, NA, NA, "4", "7... |
|||
## $ os.minor <chr> NA, NA, NA, NA, NA, "0", "2", "3", "3", "3", "0", "0", "0", "0", "0", NA, NA, NA, NA, "1", "0... |
|||
## $ os.patch <chr> NA, NA, NA, NA, NA, "3", "2", "3", "4", "5", "1", "3", "3", "3", "4", NA, NA, NA, NA, "1", "6... |
|||
## $ os.patchMinor <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... |
|||
|
|||
### Test Results |
|||
|
|||
``` r |
|||
library(uaparserjs) |
|||
library(testthat) |
|||
|
|||
date() |
|||
``` |
|||
|
|||
## [1] "Thu Aug 4 17:21:51 2016" |
|||
|
|||
``` r |
|||
test_dir("tests/") |
|||
``` |
|||
|
|||
## testthat results ======================================================================================================== |
|||
## OK: 3 SKIPPED: 0 FAILED: 0 |
|||
## |
|||
## DONE =================================================================================================================== |
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,32 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/uaparser.R |
|||
\name{ua_parse} |
|||
\alias{ua_parse} |
|||
\title{Parse a vector of user agents into a data frame} |
|||
\usage{ |
|||
ua_parse(user_agents) |
|||
} |
|||
\arguments{ |
|||
\item{user_agents}{a character vector of user agents} |
|||
} |
|||
\value{ |
|||
a \code{tibble} with columns for user agent family, major & minor versions |
|||
plus patch level along with os family and major & minor versions plus |
|||
device brand and model. |
|||
} |
|||
\description{ |
|||
Takes in a character vector of user agent strings and returns a \code{tibble} |
|||
of parsed user agents. |
|||
} |
|||
\note{ |
|||
The regex YAML import date: 2016-08-04 |
|||
} |
|||
\examples{ |
|||
ua_parse(paste0("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, ", |
|||
"like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 ", |
|||
"Chrome/15.0.874.106 Safari/535.2", collapse="")) |
|||
} |
|||
\references{ |
|||
\url{http://www.uaparser.org/} |
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/uaparserjs-package.R |
|||
\docType{package} |
|||
\name{uaparserjs} |
|||
\alias{uaparserjs} |
|||
\alias{uaparserjs-package} |
|||
\title{Parse Browser User Agent Strings into Data Frames} |
|||
\description{ |
|||
Parse Browser User Agent Strings into Data Frames |
|||
} |
|||
\author{ |
|||
Bob Rudis (@hrbrmstr) |
|||
} |
|||
|
File diff suppressed because it is too large
@ -0,0 +1,2 @@ |
|||
library(testthat) |
|||
test_check("uaparserjs") |
@ -0,0 +1,12 @@ |
|||
context("basic functionality") |
|||
test_that("we can do something", { |
|||
|
|||
res <- ua_parse(paste0("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, ", |
|||
"like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 ", |
|||
"Chrome/15.0.874.106 Safari/535.2", collapse="")) |
|||
|
|||
expect_that(res, is_a("data.frame")) |
|||
expect_that(res$ua.patch, equals("874")) |
|||
expect_that(res$os.family, equals("Ubuntu")) |
|||
|
|||
}) |
@ -0,0 +1,21 @@ |
|||
Version: 1.0 |
|||
|
|||
RestoreWorkspace: Default |
|||
SaveWorkspace: Default |
|||
AlwaysSaveHistory: Default |
|||
|
|||
EnableCodeIndexing: Yes |
|||
UseSpacesForTab: Yes |
|||
NumSpacesForTab: 2 |
|||
Encoding: UTF-8 |
|||
|
|||
RnwWeave: Sweave |
|||
LaTeX: pdfLaTeX |
|||
|
|||
StripTrailingWhitespace: Yes |
|||
|
|||
BuildType: Package |
|||
PackageUseDevtools: Yes |
|||
PackageInstallArgs: --no-multiarch --with-keep.source |
|||
PackageBuildArgs: --resave-data |
|||
PackageRoxygenize: rd,collate,namespace |
Loading…
Reference in new issue