Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move code
  • Loading branch information
nealrichardson committed Aug 22, 2019
commit d307695e088158273c7291ee2489772a1f14bcc1
1 change: 1 addition & 0 deletions r/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ Collate:
'read_table.R'
'reexports-bit64.R'
'reexports-tidyselect.R'
'to-arrow.R'
'write_arrow.R'
18 changes: 0 additions & 18 deletions r/R/Table.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@
)
)

#' Create an arrow::Table from a data frame
#'
#' @param ... arrays, chunked arrays, or R vectors
#' @param schema a schema. The default (`NULL`) infers the schema from the `...`
#'
#' @return an arrow::Table
#'
#' @export
table <- function(..., schema = NULL){
dots <- list2(...)
# making sure there are always names
if (is.null(names(dots))) {
names(dots) <- rep_len("", length(dots))
}
stopifnot(length(dots) > 0)
shared_ptr(`arrow::Table`, Table__from_dots(dots, schema))
}

#' @export
`as.data.frame.arrow::Table` <- function(x, row.names = NULL, optional = FALSE, use_threads = TRUE, ...){
Table__to_dataframe(x, use_threads = option_use_threads())
Expand Down
10 changes: 0 additions & 10 deletions r/R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,3 @@

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

#' create an [arrow::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){
`arrow::Array`$dispatch(Array__from_vector(x, type))
}
38 changes: 38 additions & 0 deletions r/R/to-arrow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
to_arrow <- function(x) {
UseMethod("to_arrow")
}

`to_arrow.arrow::RecordBatch` <- function(x) x
`to_arrow.arrow::Table` <- function(x) x

# splice the data frame as arguments of table()
# see ?rlang::list2()
`to_arrow.data.frame` <- function(x) table(!!!x)

#' Create an arrow::Table from a data frame
#'
#' @param ... arrays, chunked arrays, or R vectors
#' @param schema a schema. The default (`NULL`) infers the schema from the `...`
#'
#' @return an arrow::Table
#'
#' @export
table <- function(..., schema = NULL){
dots <- list2(...)
# making sure there are always names
if (is.null(names(dots))) {
names(dots) <- rep_len("", length(dots))
}
stopifnot(length(dots) > 0)
shared_ptr(`arrow::Table`, Table__from_dots(dots, schema))
}

#' create an [arrow::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){
`arrow::Array`$dispatch(Array__from_vector(x, type))
}
11 changes: 0 additions & 11 deletions r/R/write_arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
# specific language governing permissions and limitations
# under the License.

to_arrow <- function(x) {
UseMethod("to_arrow")
}

`to_arrow.arrow::RecordBatch` <- function(x) x
`to_arrow.arrow::Table` <- function(x) x

# splice the data frame as arguments of table()
# see ?rlang::list2()
`to_arrow.data.frame` <- function(x) table(!!!x)

#' Write Arrow formatted data
#'
#' @param x an [arrow::Table][arrow__Table], an [arrow::RecordBatch][arrow__RecordBatch] or a data.frame
Expand Down
2 changes: 1 addition & 1 deletion r/man/array.Rd

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

2 changes: 1 addition & 1 deletion r/man/table.Rd

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