Skip to content

Commit

Permalink
Replace array() with Array()
Browse files Browse the repository at this point in the history
  • Loading branch information
nealrichardson committed Sep 10, 2019
1 parent 9f52490 commit 1f6d154
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 189 deletions.
2 changes: 1 addition & 1 deletion r/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ S3method(write_feather,default)
S3method(write_feather_RecordBatch,"arrow::io::OutputStream")
S3method(write_feather_RecordBatch,character)
S3method(write_feather_RecordBatch,default)
export(Array)
export(BufferOutputStream)
export(BufferReader)
export(CompressedInputStream)
Expand All @@ -108,7 +109,6 @@ export(RecordBatchStreamWriter)
export(StatusCode)
export(TimeUnit)
export(Type)
export(array)
export(arrow_available)
export(bool)
export(boolean)
Expand Down
6 changes: 3 additions & 3 deletions r/R/ArrayData.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' @section Usage:
#'
#' ```
#' data <- array(x)$data()
#' data <- Array$create(x)$data()
#'
#' data$type()
#' data$length()
Expand All @@ -39,8 +39,8 @@
#'
#' ...
#'
#' @rdname arrow__ArrayData
#' @name arrow__ArrayData
#' @rdname ArrayData
#' @name ArrayData
`ArrayData` <- R6Class("ArrayData",
inherit = `arrow::Object`,
active = list(
Expand Down
4 changes: 2 additions & 2 deletions r/R/ChunkedArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
`arrow::ChunkedArray` <- R6Class("arrow::ChunkedArray", inherit = `arrow::Object`,
public = list(
length = function() ChunkedArray__length(self),
chunk = function(i) `Array`$dispatch(ChunkedArray__chunk(self, i)),
chunk = function(i) Array$create(ChunkedArray__chunk(self, i)),
as_vector = function() ChunkedArray__as_vector(self),
Slice = function(offset, length = NULL){
if (is.null(length)) {
Expand All @@ -50,7 +50,7 @@
active = list(
null_count = function() ChunkedArray__null_count(self),
num_chunks = function() ChunkedArray__num_chunks(self),
chunks = function() map(ChunkedArray__chunks(self), ~ `Array`$dispatch(.x)),
chunks = function() map(ChunkedArray__chunks(self), ~ Array$create(.x)),
type = function() `arrow::DataType`$dispatch(ChunkedArray__type(self))
)
)
Expand Down
51 changes: 23 additions & 28 deletions r/R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' @section Usage:
#'
#' ```
#' a <- array(x)
#' a <- Array$create(x)
#'
#' a$IsNull(i)
#' a$IsValid(i)
Expand Down Expand Up @@ -59,15 +59,16 @@
#' - `$type_id()`: type id
#' - `$Equals(other)` : is this array equal to `other`
#' - `$ApproxEquals(other)` :
#' - `$data()`: return the underlying [ArrayData][arrow__ArrayData]
#' - `$data()`: return the underlying [ArrayData][ArrayData]
#' - `$as_vector()`: convert to an R vector
#' - `$ToString()`: string representation of the array
#' - `$Slice(offset, length = NULL)` : Construct a zero-copy slice of the array with the indicated offset and length. If length is `NULL`, the slice goes until the end of the array.
#' - `$RangeEquals(other, start_idx, end_idx, other_start_idx)` :
#'
#' @rdname arrow__Array
#' @name arrow__Array
`Array` <- R6Class("Array",
#' @rdname Array
#' @name Array
#' @export
Array <- R6Class("Array",
inherit = `arrow::Object`,
public = list(
IsNull = function(i) Array__IsNull(self, i),
Expand All @@ -93,7 +94,7 @@
cast = function(target_type, safe = TRUE, options = cast_options(safe)) {
assert_that(inherits(target_type, "arrow::DataType"))
assert_that(inherits(options, "arrow::compute::CastOptions"))
`Array`$dispatch(Array__cast(self, target_type, options))
Array$create(Array__cast(self, target_type, options))
}
),
active = list(
Expand All @@ -105,22 +106,22 @@

`arrow::DictionaryArray` <- R6Class("arrow::DictionaryArray", inherit = `Array`,
public = list(
indices = function() `Array`$dispatch(DictionaryArray__indices(self)),
dictionary = function() `Array`$dispatch(DictionaryArray__dictionary(self))
indices = function() Array$create(DictionaryArray__indices(self)),
dictionary = function() Array$create(DictionaryArray__dictionary(self))
)
)

`arrow::StructArray` <- R6Class("arrow::StructArray", inherit = `Array`,
public = list(
field = function(i) `Array`$dispatch(StructArray__field(self, i)),
GetFieldByName = function(name) `Array`$dispatch(StructArray__GetFieldByName(self, name)),
Flatten = function() map(StructArray__Flatten(self), ~ `Array`$dispatch(.x))
field = function(i) Array$create(StructArray__field(self, i)),
GetFieldByName = function(name) Array$create(StructArray__GetFieldByName(self, name)),
Flatten = function() map(StructArray__Flatten(self), ~ Array$create(.x))
)
)

`arrow::ListArray` <- R6Class("arrow::ListArray", inherit = `Array`,
public = list(
values = function() `Array`$dispatch(ListArray__values(self)),
values = function() Array$create(ListArray__values(self)),
value_length = function(i) ListArray__value_length(self, i),
value_offset = function(i) ListArray__value_offset(self, i),
raw_value_offsets = function() ListArray__raw_value_offsets(self)
Expand All @@ -130,30 +131,24 @@
)
)

`Array`$dispatch <- function(xp){
a <- shared_ptr(`Array`, xp)
# Add a class method
Array$create <- function(x, type = NULL) {
if (!inherits(x, "externalptr")) {
x <- Array__from_vector(x, type)
}
a <- shared_ptr(Array, x)
if (a$type_id() == Type$DICTIONARY){
a <- shared_ptr(`arrow::DictionaryArray`, xp)
a <- shared_ptr(`arrow::DictionaryArray`, x)
} else if (a$type_id() == Type$STRUCT) {
a <- shared_ptr(`arrow::StructArray`, xp)
a <- shared_ptr(`arrow::StructArray`, x)
} else if (a$type_id() == Type$LIST) {
a <- shared_ptr(`arrow::ListArray`, xp)
a <- shared_ptr(`arrow::ListArray`, x)
}
a
}

#' @export
`length.Array` <- function(x) x$length()
length.Array <- function(x) x$length()

#' @export
`==.Array` <- function(x, y) x$Equals(y)

#' create an [Array][arrow__Array] from an R vector
#'
#' @param x R object
#' @param type Explicit [type][arrow__DataType], or NULL (the default) to infer from the data
#'
#' @export
array <- function(x, type = NULL){
`Array`$dispatch(Array__from_vector(x, type))
}
5 changes: 2 additions & 3 deletions r/man/arrow__ArrayData.Rd → r/man/ArrayData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 50 additions & 10 deletions r/man/array.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 0 additions & 57 deletions r/man/arrow__Array.Rd

This file was deleted.

Loading

0 comments on commit 1f6d154

Please sign in to comment.