-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathstreaming.R
85 lines (53 loc) · 2.04 KB
/
streaming.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
library(RJSONIO); f= "inst/sampleData/web.json"; .Call("R_json_parser_test_stream", f)
library(RJSONIO); f= "inst/sampleData/web.json"; .Call("R_json_parser_test_stream_str", '[1,2, 3]{"a": [true, false]}')
library(RJSONIO); f= "inst/sampleData/web.json"; .Call("R_json_parser_test_stream_str", paste(readLines("inst/sampleData/web.json"), collapse = "\n"))
library(RJSONIO)
val = list(a = 1:100, b = 100:1, c = rnorm(1000))
xx = toJSON(val, digits = 16)
ans = .Call("R_json_parser_test_stream_str", xx)
# in chunks
ans = .Call("R_json_parser_test_stream_chunk", xx)
all.equal(val, ans)
z = replicate(400, {ans = .Call("R_json_parser_test_stream_chunk", xx); all.equal(val, ans)})
library(RJSONIO)
val = list(a = 1:100, b = 100:1, c = rnorm(1000))
xx = toJSON(val, digits = 16)
con = textConnection(xx)
getData = function() readLines(con, n = 1)
ans = .Call("R_json_parser_test_stream_chunk_con", quote(getData()))
all.equal(ans, val)
library(RJSONIO)
val = list(a = 1:100, b = 100:1, c = rnorm(1000))
xx = toJSON(val, digits = 16)
con = textConnection(xx)
e = substitute(readLines(con, n = 1), list(con = con))
ans = .Call("R_json_parser_test_stream_chunk_con", e)
all.equal(ans, val)
####################
library(RJSONIO)
val = list(a = 1:100, b = 100:1, c = rnorm(1000))
xx = toJSON(val, digits = 16)
z = replicate(40, {
con = textConnection(xx)
e = substitute(readLines(con, n = 1), list(con = con))
ans = .Call("R_json_parser_init_from_con", e, NULL, 14L, NULL, TRUE)
all.equal(ans, val)
})
table(z)
# With a callback
library(RJSONIO)
val = list(a = 1:100, b = 100:1, c = rnorm(1000))
xx = toJSON(val, digits = 16)
con = textConnection(xx)
e = substitute(readLines(con, n = 1), list(con = con))
f = function(x)
print(x)
ans = .Call("R_json_parser_init_from_con", e, f, 14L, NULL, TRUE)
all.equal(ans, val)
library(RJSONIO)
xx = '[1,2, 3]{"a": [true, false]}'
con = textConnection(xx)
e = substitute(readLines(con, n = 1), list(con = con))
f = function(x)
print(sum(unlist(x)))
ans = .Call("R_json_parser_init_from_con", e, f)