Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding fparse, fload and more polish #32

Merged
merged 14 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
^.*\.tar\.gz$
^docs
\.travis\.yml
\.clang-format$
\.covrignore$
^local
32 changes: 32 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
Language: Cpp
Standard: Cpp11
BasedOnStyle: LLVM

AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
AlignTrailingComments: true

AllowShortFunctionsOnASingleLine: Inline

AlwaysBreakTemplateDeclarations: true

BinPackArguments: false
BinPackParameters: false

BreakBeforeTernaryOperators: true

ColumnLimit: 100

DerivePointerAlignment: false

IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4

MaxEmptyLinesToKeep: 2

PointerAlignment: Left

SortIncludes: false
SortUsingDeclarations: false
2 changes: 2 additions & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inst/include/simdjson.h
inst/include/simdjson.cpp
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ env:

jobs:
include:
- name: gcc-7
env: CXX11="g++-7" CXX17="g++-7" CC="gcc-7"
- name: gcc-8
env: CXX11="g++-8" CXX17="g++-8" CC="gcc-8"
- name: gcc-9
Expand Down
27 changes: 27 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
2020-07-05 Brendan Knapp <brendan.g.knapp@gmail.com>

* DESCRIPTION (Imports): add utils to Imports
* NAMESPACE: added importFrom(utils, download.file)

* R/fparse: New functions fparse and fload (plus tests and docs)
* R/fload: Idem
* man/fparse.Rd: Idem
* inst/tinytest/test_fparse_fload.R: Idem

* src/deserialize.cpp: add options for errors and single JSON nulls,
guard gcc-7 from disabling simdjson exceptions, expand tests
* inst/include/RcppSimdJson/common.hpp: Idem
* inst/include/RcppSimdJson/deserialize.hpp: Idem
* inst/include/RcppSimdJson/deserialize/dataframe.hpp: Idem
* inst/include/RcppSimdJson/deserialize/matrix.hpp: Idem
* inst/include/RcppSimdJson/deserialize/scalar.hpp: Idem
* inst/include/RcppSimdJson/deserialize/simplify.hpp: Idem
* inst/include/RcppSimdJson/deserialize/vector.hpp: Idem
* inst/include/RcppSimdJson/deserialize/Type_Doctor.hpp: Idem

* .travis.yml: Add (now passing) g++-7 to Travis Matrix

2020-07-04 Dirk Eddelbuettel <edd@debian.org>

* .travis.yml: Rewritten as matrix over g++ 8, 9, and 10

2020-07-02 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll version and date
Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: RcppSimdJson
Type: Package
Title: 'Rcpp' Bindings for the 'simdjson' Header-Only Library for 'JSON' Parsing
Version: 0.0.6.2
Date: 2020-07-02
Version: 0.0.6.4
Date: 2020-07-05
Author: Dirk Eddelbuettel, Brendan Knapp
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Description: The 'JSON' format is ubiquitous for data interchange, and the
Expand All @@ -13,7 +13,7 @@ Description: The 'JSON' format is ubiquitous for data interchange, and the
at present still a fairly thin and not fully complete wrapper that does not
aim to replace the existing and excellent 'JSON' packages for R.
License: GPL (>= 2)
Imports: Rcpp
Imports: Rcpp, utils
LinkingTo: Rcpp
Suggests: bit64, tinytest
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
useDynLib(RcppSimdJson, .registration=TRUE)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
importFrom(utils, download.file)
77 changes: 4 additions & 73 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,81 +1,12 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Deserialize JSON into R Objects
#'
#' @param json \code{character()} containing one or more strings of JSON data.
#'
#' @param json_pointer \code{character(1L)}, default: \code{""}
#'
#' @param empty_array default: \code{NULL}. Any R object to return for empty JSON arrays.
#'
#' @param empty_object default: \code{NULL}. Any R object to return for empty JSON objects.
#'
#' @param simplify_to \code{integer(1L)}, default: \code{0L}.
#' Maximum simplification level.
#' 0: data frame, 1: matrix, 2: vector, 3: list (no simplification)
#'
#' @param type_policy \code{integer(1L)}, default: \code{0L}.
#' Level of type strictness.
#' 0: merge everything, 1: merge numbers, 2: strict (mixed types are not merged)
#'
#' @param int64_r_type \code{integer(1L)} default: \code{0L}
#' How to return big integers to R.
#' 0: \code{double}, 1: string, 2: \code{bit64::integer64}-compatible number
#'
#' @details
#' Instead of using \code{lapply()} for vectors containing multiple strings/file paths,
#' just use \code{.deserialize_json()} and \code{.load_json()} directly as they are vectorized
#' (in the R sense). This is much more efficient as the underlying \code{simdjson::parser} can
#' reuse internal buffers between parses. Since the overwhelming majority of JSON objects
#' parsed will not result in R scalars, a \code{list()} is always returned when multiple items
#' are passed to \code{.deserialize_json()} or \code{.load_json()}. Also in keeping with
#' \code{lapply()}'s behavior, if the data passed has \code{names()}, the returned object will
#' have the same names.
#'
#' @keywords internal
#'
#' @examples
#' # .deserialize_json() ======================================================
#' RcppSimdJson:::.deserialize_json('[[1,2,3],[4,5,6]]')
#'
#' RcppSimdJson:::.deserialize_json(
#' '[{"a":1,"b":true},{"a":2,"b":false,"c":null}]'
#' )
#'
#' RcppSimdJson:::.deserialize_json(
#' c(
#' json1 = "[[1,2,3],[4,5,6]]",
#' json2 = '[{"a":1,"b":true},{"a":2,"b":false,"c":null}]'
#' )
#' )
#'
.deserialize_json <- function(json, json_pointer = "", empty_array = NULL, empty_object = NULL, simplify_to = 0L, type_policy = 0L, int64_r_type = 0L) {
.Call(`_RcppSimdJson_deserialize_json`, json, json_pointer, empty_array, empty_object, simplify_to, type_policy, int64_r_type)
.deserialize_json <- function(json, json_pointer = "", empty_array = NULL, empty_object = NULL, single_null = NULL, error_ok = FALSE, on_error = NULL, simplify_to = 0L, type_policy = 0L, int64_r_type = 0L) {
.Call(`_RcppSimdJson_deserialize_json`, json, json_pointer, empty_array, empty_object, single_null, error_ok, on_error, simplify_to, type_policy, int64_r_type)
}

#' @rdname dot-deserialize_json
#'
#' @param file_path \code{character()} containing one or more paths to files containing
#' JSON data.
#'
#' @examples
#' # .load_json() =============================================================
#' single_file <- system.file("jsonexamples", "small", "flatadversarial.json",
#' package = "RcppSimdJson")
#' RcppSimdJson:::.load_json(single_file)
#'
#' multiple_files <- vapply(
#' c("flatadversarial.json", "adversarial.json"),
#' function(.x) {
#' system.file("jsonexamples/small", .x, package = "RcppSimdJson")
#' },
#' character(1L)
#' )
#' RcppSimdJson:::.load_json(multiple_files)
#'
.load_json <- function(file_path, json_pointer = "", empty_array = NULL, empty_object = NULL, simplify_to = 0L, type_policy = 0L, int64_r_type = 0L) {
.Call(`_RcppSimdJson_load_json`, file_path, json_pointer, empty_array, empty_object, simplify_to, type_policy, int64_r_type)
.load_json <- function(file_path, json_pointer = "", empty_array = NULL, empty_object = NULL, single_null = NULL, error_ok = FALSE, on_error = NULL, simplify_to = 0L, type_policy = 0L, int64_r_type = 0L) {
.Call(`_RcppSimdJson_load_json`, file_path, json_pointer, empty_array, empty_object, single_null, error_ok, on_error, simplify_to, type_policy, int64_r_type)
}

.exceptions_enabled <- function() {
Expand Down
Loading