ateucher commented on code in PR #13336:
URL: https://github.com/apache/arrow/pull/13336#discussion_r892692015


##########
r/R/dplyr.R:
##########
@@ -24,6 +24,21 @@ arrow_dplyr_query <- function(.data) {
   # RecordBatch, or Dataset) and the state of the user's dplyr query--things
   # like selected columns, filters, and group vars.
   # An arrow_dplyr_query can contain another arrow_dplyr_query in .data
+
+  supported <- c(
+    "Dataset", "RecordBatch", "RecordBatchReader",
+    "Table", "arrow_dplyr_query", "data.frame"
+  )
+  if (!inherits(.data, supported)) {
+    stop(
+      "'dataset' must be a ",

Review Comment:
   The problem with `substitute(.data)` is that it depends on the depth of the 
call stack: 
   
   ``` r
   write_dataset(4)
   #> Error: '.data' must be a Dataset, RecordBatch, RecordBatchReader, Table, 
arrow_dplyr_query, or data.frame, not "numeric"
   as_adq(4)
   #> Error: '.data' must be a Dataset, RecordBatch, RecordBatchReader, Table, 
arrow_dplyr_query, or data.frame, not "numeric"
   arrow_dplyr_query(4)
   #> Error: '4' must be a Dataset, RecordBatch, RecordBatchReader, Table, 
arrow_dplyr_query, or data.frame, not "numeric"
   ```
   
   Using `substitute(.data, parent.frame())` gets closer - not consistent, but 
also not wrong:
   
   ``` r
   write_dataset(4)
   #> Error: 'dataset' must be a Dataset, RecordBatch, RecordBatchReader, 
Table, arrow_dplyr_query, or data.frame, not "numeric"
   as_adq(4)
   #> Error: '4' must be a Dataset, RecordBatch, RecordBatchReader, Table, 
arrow_dplyr_query, or data.frame, not "numeric"
   arrow_dplyr_query(4)
   #> Error: '.data' must be a Dataset, RecordBatch, RecordBatchReader, Table, 
arrow_dplyr_query, or data.frame, not "numeric"
   ```
   
   `arrow_dplyr_query()` is [only ever called inside `collapse()` 
methods](https://github.com/apache/arrow/blob/0f2e580bcf082ea74ea6df397ba62f1d2baa0aea/r/R/dplyr.R#L76-L80),
 and `as_adq()` is not exported, so you could argue that pushing it back up to 
`write_dataset()` would be best (and/or create S3 methods for `write_dataset`).



-- 
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]

Reply via email to