Skip to content

Commit ae55f8b

Browse files
..
1 parent 767e9d9 commit ae55f8b

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

r/.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
^README\.Rmd$
44
src/.clang-format
55
LICENSE.md
6-
^README\.Rmd$
6+
^data-raw$

r/R/R6.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ field <- function(name, type) {
426426
)
427427

428428
`arrow::Schema` <- R6Class("arrow::Schema",
429-
inherit = `arrow::Object`
429+
inherit = `arrow::Object`,
430+
public = list(
431+
ToString = function() Schema_ToString(self)
432+
)
430433
)
431434

432435
#' @rdname DataType

r/data-raw/test.R

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
library(tidyverse)
2+
library(arrow)
3+
4+
# meta data
5+
(t1 <- int32())
6+
(t2 <- utf8())
7+
(t5 <- timestamp(unit = TimeUnit$MILLI))
8+
9+
# lists
10+
list_of(t1)
11+
12+
# shema
13+
schema(x = int32(), y = float64())
14+
15+
# :scream_cat:
16+
#
17+
# pa.schema(
18+
# [
19+
# pa.field('x', pa.int32()),
20+
# pa.field('y', pa.float64())
21+
# ]
22+
# )
23+
#
24+
25+
schema(x = int32(), y = list_of(float64()))
26+
27+
#------- arrays
28+
29+
# arr = pa.array([1, 2, 3])
30+
arr <- array(1:3, 5:80)
31+
arr
32+
arr$as_vector()
33+
34+
#------- read_arrow / write_arrow
35+
tbl <- tibble(x=1:10, y=rnorm(10))
36+
write_arrow(tbl, "/tmp/test.arrow")
37+
readr::write_rds(tbl, "/tmp/test.rds")
38+
fs::file_info(c("/tmp/test.arrow", "/tmp/test.rds"))
39+
40+
(data <- read_arrow("/tmp/test.arrow"))
41+
42+
# tibble <-> arrow::RecordBatch
43+
(batch <- record_batch(tbl))
44+
batch$num_columns()
45+
batch$num_rows()
46+
batch$to_file("/tmp/test")
47+
readBin("/tmp/test", what = raw(), n = 1000)
48+
batch$schema()
49+
all.equal(tbl, data)
50+
51+
batch <- read_record_batch("/tmp/test")
52+
batch$schema()
53+
batch$column(0)
54+
batch$column(0)$as_vector()
55+
56+
as_tibble(batch)
57+
58+
# tibble <-> arrow::Table
59+
tab <- arrow::table(tbl)
60+
tab
61+
tab$schema()
62+
tab$num_columns()
63+
tab$num_rows()
64+
65+
# read_arrow, write_arrow
66+
tbl <- tibble(x = rnorm(20), y = seq_len(20))
67+
write_arrow(tbl, tf)
68+

0 commit comments

Comments
 (0)