paleolimbot commented on code in PR #35543:
URL: https://github.com/apache/arrow/pull/35543#discussion_r1237227776
##########
r/R/dplyr-collect.R:
##########
@@ -192,5 +192,6 @@ implicit_schema <- function(.data) {
aggregate_types(.data, hash, old_schm)
)
}
- schema(!!!new_fields)
+
+ schema(new_fields)
Review Comment:
If you feel strongly about the ability to pass a bare list instead of
`!!!bare_list` I think this is a better fit for a separate PR: it is not
related to the ability to use `schema()` on a
Dataset/ArrowTabular/arrow_dplyr_query and is a departure from behaviour
elsewhere in the package (e.g., none of `record_batch()`, `arrow_table()`, or
`struct()` support this).
##########
r/R/schema.R:
##########
@@ -244,10 +230,59 @@ print_schema_fields <- function(s) {
paste(map_chr(s$fields, ~ .$ToString()), collapse = "\n")
}
-#' @param ... [fields][field] or field name/[data type][data-type] pairs
+#' Schemas
+#'
+#' Create a schema or extract one from an object.
+#'
+#' @seealso [Schema] for detailed documentation of the Schema R6 object
+#' @param ... [fields][field], field name/[data type][data-type] pairs, or
object from which to extract a schema
+#' @examples
+#' # Create schema using pairs of field names and data types
+#' schema(a = int32(), b = float64())
+#'
+#' # Create schema using fields
+#' schema(
+#' field("b", double()),
+#' field("c", bool(), nullable = FALSE),
+#' field("d", string())
+#' )
+#'
+#' # Extract schemas from objects
+#' df <- data.frame(col1 = 2:4, col2 = c(0.1, 0.3, 0.5))
+#' tab1 <- arrow_table(df)
+#' schema(tab1)
+#' tab2 <- arrow_table(df, schema = schema(col1 = int8(), col2 = float32()))
+#' schema(tab2)
+#' @export
+schema <- function(...) {
+ dots <- list2(...)
+
+ if (length(dots) == 1 && !is.list(dots[[1]]) && is.null(names(dots)) &&
!inherits(dots[[1]], "Field")) {
+ return(infer_schema(dots[[1]]))
+ }
+
+ Schema$create(...)
Review Comment:
As above, if you feel strongly about this I think it is a better fit for
another PR: our usage everywhere else in the package is to capture the dots
once using `list2()` and use `!!!` if they need to be passed on to another
function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]