Skip to content

Commit 51ceccf

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1303f31 + 461c416 commit 51ceccf

File tree

106 files changed

+1015
-1073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1015
-1073
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ vignettes/framed.sty$
3131
^revdep$
3232
^CODE_OF_CONDUCT\.md$
3333
^\.github$
34+
^air.toml$
35+

.github/workflows/R-CMD-check.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
matrix:
1818
config:
1919
- {os: macOS-latest, r: 'release'}
20+
- {os: macOS-15, r: 'next'}
2021
- {os: windows-2022, r: 'devel'}
2122
- {os: windows-latest, r: '4.1'}
2223
- {os: windows-latest, r: '3.6'}
@@ -47,3 +48,5 @@ jobs:
4748
extra-packages: rcmdcheck
4849

4950
- uses: r-lib/actions/check-r-package@v2
51+
env:
52+
MAKEFLAGS: -j4

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: jsonlite
2-
Version: 1.8.9.999
3-
Title: A Robust, High Performance JSON Parser and Generator for R (adjusted for use in MIRO)
2+
Version: 2.0.0.999
3+
Title: A Simple and Robust JSON Parser and Generator for R (adjusted for use in MIRO)
44
License: MIT + file LICENSE
55
Depends: methods
66
Authors@R: c(
@@ -30,6 +30,6 @@ Suggests:
3030
rmarkdown,
3131
R.rsp,
3232
sf
33-
RoxygenNote: 7.2.3
33+
RoxygenNote: 7.3.2
3434
Encoding: UTF-8
3535
Roxygen: list(markdown = TRUE)

NEWS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2.0.0
2+
- Output for toJSON(x, pretty = p) where p is a number has changed: now uses
3+
the same r-based indent system as for pretty = TRUE. To get the old format,
4+
run json output through prettify().
5+
- Both toJSON() and prettify() support now can use tabs instead of spaces by
6+
setting a negative number as indent/pretty argument.
7+
- Fix an ubsan warning in prettify/minify in libyajl
8+
- Reformatted code with air
9+
10+
1.9.1
11+
- Fix a unit test in R 4.5 due to the new 'penguins_raw' dataset
12+
13+
1.9.0
14+
- Remove legacy modp_stdint.h which breaks in C23 on Windows (R-4.5)
15+
116
1.8.9
217
- Fix memory leak in base64 decoder
318
- Update maintainer email address

R/apply_by_pages.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
apply_by_pages <- function(x, FUN, pagesize, verbose, ...){
1+
apply_by_pages <- function(x, FUN, pagesize, verbose, ...) {
22
stopifnot(is.data.frame(x))
33
nr <- nrow(x)
4-
npages <- nr %/% pagesize;
5-
lastpage <- nr %% pagesize;
4+
npages <- nr %/% pagesize
5+
lastpage <- nr %% pagesize
66

77
out <- as.list(rep(NA, npages + as.logical(lastpage)))
8-
for(i in seq_len(npages)){
9-
from <- pagesize * (i-1) + 1;
8+
for (i in seq_len(npages)) {
9+
from <- pagesize * (i - 1) + 1
1010
to <- pagesize * i
11-
out[[i]] <- FUN(x[from:to, ,drop = FALSE], ...)
12-
if(verbose) cat("\rProcessed", i * pagesize, "rows...")
11+
out[[i]] <- FUN(x[from:to, , drop = FALSE], ...)
12+
if (verbose) cat("\rProcessed", i * pagesize, "rows...")
1313
}
1414

15-
if(lastpage){
16-
from <- nr - lastpage + 1;
17-
out[[npages + 1]] <- FUN(x[from:nr, ,drop = FALSE], ...)
15+
if (lastpage) {
16+
from <- nr - lastpage + 1
17+
out[[npages + 1]] <- FUN(x[from:nr, , drop = FALSE], ...)
1818
}
19-
if(verbose) cat("\rComplete! Processed total of", nr, "rows.\n")
19+
if (verbose) cat("\rComplete! Processed total of", nr, "rows.\n")
2020
out
2121
}
2222

2323
#this is another slightly slower implementation
24-
apply_by_pages2 <- function(x, FUN, pagesize, verbose, ...){
24+
apply_by_pages2 <- function(x, FUN, pagesize, verbose, ...) {
2525
x2 <- split(x, seq_len(nrow(x)) %/% pagesize)
26-
for(page in x2){
27-
if(verbose) message("Writing ", nrow(page), " lines (", ").")
26+
for (page in x2) {
27+
if (verbose) message("Writing ", nrow(page), " lines (", ").")
2828
FUN(page)
2929
}
3030
invisible()

R/as.scalar.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
as.scalar <- function(obj) {
22
# Lists can never be a scalar (this can arise if a dataframe contains a column
33
# with lists)
4-
if(length(dim(obj)) > 1){
5-
if(!identical(nrow(obj), 1L)){
6-
warning("Tried to use as.scalar on an array or dataframe with ", nrow(obj), " rows.", call.=FALSE)
4+
if (length(dim(obj)) > 1) {
5+
if (!identical(nrow(obj), 1L)) {
6+
warning("Tried to use as.scalar on an array or dataframe with ", nrow(obj), " rows.", call. = FALSE)
77
return(obj)
88
}
9-
} else if(!identical(length(obj), 1L)) {
10-
warning("Tried to use as.scalar on an object of length ", length(obj), call.=FALSE)
9+
} else if (!identical(length(obj), 1L)) {
10+
warning("Tried to use as.scalar on an object of length ", length(obj), call. = FALSE)
1111
return(obj)
12-
} else if(is.namedlist(obj)){
13-
warning("Tried to use as.scalar on a named list.", call.=FALSE)
12+
} else if (is.namedlist(obj)) {
13+
warning("Tried to use as.scalar on a named list.", call. = FALSE)
1414
return(obj)
1515
}
1616

R/asJSON.AAAgeneric.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ setGeneric("asJSON", function(x, ...) {
22
standardGeneric("asJSON")
33
})
44

5-
if(getRversion() < "4"){
5+
if (getRversion() < "4") {
66
setOldClass("AsIs")
77
setOldClass("integer64")
88
setOldClass(c("hms", "difftime"))

R/asJSON.AsIs.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
setMethod("asJSON", "AsIs", function(x, auto_unbox = FALSE, ...) {
2-
32
# Strip off the AsIs class so we can dispatch to other asJSON methods.
43
class(x) <- setdiff(class(x), "AsIs")
54

65
if (is.atomic(x) && length(x) == 1) {
76
# Never auto_unbox single values when wrapped with I()
87
asJSON(x, auto_unbox = FALSE, ...)
9-
108
} else {
119
asJSON(x, auto_unbox = auto_unbox, ...)
1210
}

R/asJSON.Date.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
setMethod("asJSON", "Date", function(x, Date = c("ISO8601", "epoch"), always_decimal = FALSE, ...) {
2-
32
# Validate argument
43
Date <- match.arg(Date)
54

65
# select a schema
7-
output <- switch(Date,
6+
output <- switch(
7+
Date,
88
ISO8601 = format(x),
99
epoch = unclass(x),
1010
default = stop("Invalid argument for 'Date':", Date)

R/asJSON.NULL.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Note that this is different from RJSONIO because null values are NA.
22
setMethod("asJSON", "NULL", function(x, null = "list", ...) {
3-
if(null == "null"){
3+
if (null == "null") {
44
return("null")
55
} else {
66
return("{}")

R/asJSON.POSIXt.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
setMethod("asJSON", "POSIXt", function(x, POSIXt = c("string", "ISO8601", "epoch",
2-
"mongo"), UTC = FALSE, digits, time_format = NULL, always_decimal = FALSE, ...) {
1+
setMethod("asJSON", "POSIXt", function(x, POSIXt = c("string", "ISO8601", "epoch", "mongo"), UTC = FALSE, digits, time_format = NULL, always_decimal = FALSE, ...) {
32
# note: UTC argument doesn't seem to be working consistently maybe use ?format
43
# instead of ?as.character
54

@@ -17,10 +16,10 @@ setMethod("asJSON", "POSIXt", function(x, POSIXt = c("string", "ISO8601", "epoch
1716
}
1817

1918
# Strings
20-
if(is.null(time_format)){
21-
time_format <- if(POSIXt == "string"){
19+
if (is.null(time_format)) {
20+
time_format <- if (POSIXt == "string") {
2221
""
23-
} else if(isTRUE(UTC)){
22+
} else if (isTRUE(UTC)) {
2423
"%Y-%m-%dT%H:%M:%SZ"
2524
} else {
2625
"%Y-%m-%dT%H:%M:%S"
@@ -34,16 +33,15 @@ setMethod("asJSON", "POSIXt", function(x, POSIXt = c("string", "ISO8601", "epoch
3433
}
3534
})
3635

37-
asJSON_posix_mongo <- function(x, collapse = TRUE, indent = NA_integer_, ...){
36+
asJSON_posix_mongo <- function(x, collapse = TRUE, indent = NA_integer_, ...) {
3837
if (inherits(x, "POSIXlt")) {
3938
x <- as.POSIXct(x)
4039
}
4140
df <- data.frame("$date" = floor(unclass(x) * 1000), check.names = FALSE)
42-
if(inherits(x, "scalar"))
43-
class(df) <- c("scalar", class(df))
41+
if (inherits(x, "scalar")) class(df) <- c("scalar", class(df))
4442
tmp <- asJSON(df, digits = NA, always_decimal = FALSE, ..., collapse = FALSE)
4543
tmp[is.na(x)] <- asJSON(NA_character_, collapse = FALSE, ...)
46-
if(isTRUE(collapse)){
44+
if (isTRUE(collapse)) {
4745
collapse(tmp, inner = FALSE, indent = indent)
4846
} else {
4947
tmp

R/asJSON.array.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
asjson_array_fun <- function(x, collapse = TRUE, na = NULL, oldna = NULL,
2-
matrix = c("rowmajor", "columnmajor"), auto_unbox = FALSE, keep_vec_names = FALSE,
3-
indent = NA_integer_, ...) {
4-
5-
matrix <- match.arg(matrix);
1+
asjson_array_fun <- function(x, collapse = TRUE, na = NULL, oldna = NULL, matrix = c("rowmajor", "columnmajor"), auto_unbox = FALSE, keep_vec_names = FALSE, indent = NA_integer_, ...) {
2+
matrix <- match.arg(matrix)
63

74
# reset na arg when called from data frame
8-
if(identical(na, "NA")){
9-
na <- oldna;
5+
if (identical(na, "NA")) {
6+
na <- oldna
107
}
118

129
# 1D arrays are vectors
13-
if(length(dim(x)) < 2){
14-
return(asJSON(c(x), matrix = matrix, na = na, indent = indent + 2L, ...))
10+
if (length(dim(x)) < 2) {
11+
return(asJSON(c(x), matrix = matrix, na = na, indent = indent_increment(indent), ...))
1512
}
1613

1714
# if collapse == FALSE, then this matrix is nested inside a data frame,
1815
# and therefore row major must be forced to match dimensions
19-
if(identical(matrix, "columnmajor") && collapse == FALSE){
20-
return(apply(x, 1, asJSON, matrix = matrix, na = na, indent = indent + 2L, ...))
16+
if (identical(matrix, "columnmajor") && collapse == FALSE) {
17+
return(apply(x, 1, asJSON, matrix = matrix, na = na, indent = indent_increment(indent), ...))
2118
}
2219

2320
# dont pass auto_unbox (never unbox within matrix)
2421
m <- asJSON(c(x), collapse = FALSE, matrix = matrix, na = na, ...)
2522
dim(m) <- dim(x)
26-
tmp <- if(length(dim(x)) == 2 && identical(matrix, "rowmajor")){
23+
tmp <- if (length(dim(x)) == 2 && identical(matrix, "rowmajor")) {
2724
# Faster special case for 2D matrices
28-
row_collapse(m, indent = indent + 2L)
25+
row_collapse(m, indent = indent_increment(indent))
2926
} else {
3027
collapse_array(m, columnmajor = identical(matrix, "columnmajor"), indent = indent)
3128
}
@@ -41,4 +38,3 @@ asjson_array_fun <- function(x, collapse = TRUE, na = NULL, oldna = NULL,
4138
# Some objects have class Matrix but not class Array
4239
setMethod("asJSON", "array", asjson_array_fun)
4340
setMethod("asJSON", "matrix", asjson_array_fun)
44-

R/asJSON.character.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
setMethod("asJSON", "character", function(x, collapse = TRUE, na = c("null", "string", "NA"),
2-
auto_unbox = FALSE, keep_vec_names = FALSE, indent = NA_integer_, ...) {
3-
1+
setMethod("asJSON", "character", function(x, collapse = TRUE, na = c("null", "string", "NA"), auto_unbox = FALSE, keep_vec_names = FALSE, indent = NA_integer_, ...) {
42
# Needed for multi-byte Windows locales
53
# See: https://github.com/jeroen/jsonlite/issues/329
64
x <- enc2utf8(x)
75

86
# shiny legacy exception
9-
if(isTRUE(keep_vec_names) && length(names(x))){
7+
if (isTRUE(keep_vec_names) && length(names(x))) {
108
warn_keep_vec_names()
119
return(asJSON(as.list(x), na = na, auto_unbox = TRUE, collapse = collapse, ...))
1210
}
@@ -26,15 +24,15 @@ setMethod("asJSON", "character", function(x, collapse = TRUE, na = c("null", "st
2624
na <- match.arg(na)
2725
if (na %in% c("null")) {
2826
tmp[missings] <- "null"
29-
} else if(na %in% "string") {
27+
} else if (na %in% "string") {
3028
tmp[missings] <- "\"NA\""
3129
} else {
3230
tmp[missings] <- NA_character_
3331
}
3432
}
3533

36-
if(isTRUE(auto_unbox) && length(tmp) == 1){
37-
return(tmp);
34+
if (isTRUE(auto_unbox) && length(tmp) == 1) {
35+
return(tmp)
3836
}
3937

4038
# this is almost always true, except for class 'scalar'

R/asJSON.complex.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
setMethod("asJSON", "complex", function(x, digits = 5, collapse = TRUE, complex = c("string",
2-
"list"), na = c("string", "null", "NA"), oldna = NULL, ...) {
3-
1+
setMethod("asJSON", "complex", function(x, digits = 5, collapse = TRUE, complex = c("string", "list"), na = c("string", "null", "NA"), oldna = NULL, ...) {
42
# validate
5-
na <- match.arg(na);
3+
na <- match.arg(na)
64
complex <- match.arg(complex)
75

86
#turn into strings
97
if (complex == "string") {
108
#default NA is "NA"
119
mystring <- prettyNum(x = x, digits = digits)
12-
if (any(missings <- which(!is.finite(x)))){
10+
if (any(missings <- which(!is.finite(x)))) {
1311
if (na %in% c("null", "NA")) {
14-
mystring[missings] <- NA_character_;
12+
mystring[missings] <- NA_character_
1513
}
1614
}
1715
asJSON(mystring, collapse = collapse, na = na, ...)
1816
} else {
19-
if(na == "NA"){
20-
na <- oldna;
17+
if (na == "NA") {
18+
na <- oldna
2119
}
2220
asJSON(list(real = Re(x), imaginary = Im(x)), na = na, digits = digits, ...)
2321
}

0 commit comments

Comments
 (0)