You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/18 15:10:41 UTC

[GitHub] [arrow] thisisnic commented on a change in pull request #12546: ARROW-15814: [R][DOCS] Improve documentation for cast()

thisisnic commented on a change in pull request #12546:
URL: https://github.com/apache/arrow/pull/12546#discussion_r830064575



##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()
 #' bool()
 #' struct(a = int32(), b = double())
 #' timestamp("ms", timezone = "CEST")
 #' time64("ns")
+#'
+#' # Use the cast method to change the type of data contained in Arrow Objects.

Review comment:
       ```suggestion
   #' # Use the cast method to change the type of data contained in Arrow objects
   ```

##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()

Review comment:
       This will mean that we don't generate any of the examples if `arrow_with_dataset()` is `FALSE` though; even the ones which don't require Datasets.  How about using `\dontrun` instead for the `dplyr` block?

##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()
 #' bool()
 #' struct(a = int32(), b = double())
 #' timestamp("ms", timezone = "CEST")
 #' time64("ns")
+#'
+#' # Use the cast method to change the type of data contained in Arrow Objects.
+#' # Please check the documentation of each data object class for details.
+#' Scalar$create(0L)$cast(int64())$cast(timestamp("ns"))

Review comment:
       Let's break this example up into two lines to make it easier to read - one for object creation and a separate operation for casting the object to a different type.
   
   Please also just use a single cast in this.

##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()
 #' bool()
 #' struct(a = int32(), b = double())
 #' timestamp("ms", timezone = "CEST")
 #' time64("ns")
+#'
+#' # Use the cast method to change the type of data contained in Arrow Objects.
+#' # Please check the documentation of each data object class for details.
+#' Scalar$create(0L)$cast(int64())$cast(timestamp("ns"))
+#' Array$create(0L)$cast(int64())$cast(timestamp("s", timezone = "UTC"))
+#' chunked_array(0L, 1L)$cast(date32())
+#'
+#' # You can also use `cast()` in dplyr query.
+#' library(dplyr)
+#' data.frame(col1 = 1:10, col2 = 1:10) %>%
+#'   arrow_table() %>%
+#'   mutate(
+#'     col1 = cast(col1, string()),
+#'     col2 = cast(col2, date32())
+#'   ) %>%
+#'   compute()

Review comment:
       Can we instead do something like `arrow_table(mtcars)` to reduce the number of lines of code in this example?

##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()
 #' bool()
 #' struct(a = int32(), b = double())
 #' timestamp("ms", timezone = "CEST")
 #' time64("ns")
+#'
+#' # Use the cast method to change the type of data contained in Arrow Objects.
+#' # Please check the documentation of each data object class for details.
+#' Scalar$create(0L)$cast(int64())$cast(timestamp("ns"))
+#' Array$create(0L)$cast(int64())$cast(timestamp("s", timezone = "UTC"))

Review comment:
       Same as before - 2 lines and just 1 cast please.

##########
File path: r/R/type.R
##########
@@ -320,11 +320,27 @@ NestedType <- R6Class("NestedType", inherit = DataType)
 #' @return An Arrow type object inheriting from DataType.
 #' @export
 #' @seealso [dictionary()] for creating a dictionary (factor-like) type.
-#' @examplesIf arrow_available()
+#' @examplesIf arrow_available() && arrow_with_dataset()
 #' bool()
 #' struct(a = int32(), b = double())
 #' timestamp("ms", timezone = "CEST")
 #' time64("ns")
+#'
+#' # Use the cast method to change the type of data contained in Arrow Objects.
+#' # Please check the documentation of each data object class for details.
+#' Scalar$create(0L)$cast(int64())$cast(timestamp("ns"))
+#' Array$create(0L)$cast(int64())$cast(timestamp("s", timezone = "UTC"))
+#' chunked_array(0L, 1L)$cast(date32())
+#'
+#' # You can also use `cast()` in dplyr query.

Review comment:
       ```suggestion
   #' # You can also use `cast()` in an Arrow dplyr query.
   ```




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org