jonkeane commented on a change in pull request #11668:
URL: https://github.com/apache/arrow/pull/11668#discussion_r748380013



##########
File path: r/tests/testthat/test-csv.R
##########
@@ -378,3 +378,10 @@ test_that("time mapping work as expected (ARROW-13624)", {
 
   expect_equal(df, tbl, ignore_attr = "tzone")
 })
+
+test_that("Writing a CSV errors when unsupported (yet) readr args are used", {
+  expect_error(
+    write_csv_arrow(tbl, csv_file, append = FALSE),
+    "The following argument is not yet supported in Arrow: \"append\""
+  )
+})

Review comment:
       Thanks for proactively adding the error test, that's great!

##########
File path: r/R/csv.R
##########
@@ -623,8 +632,38 @@ readr_to_csv_convert_options <- function(na,
 #' @include arrow-package.R
 write_csv_arrow <- function(x,
                             sink,
+                            na = NULL,
+                            append = NULL,
+                            quote = NULL,
+                            escape = NULL,
+                            eol = NULL,
+                            num_threads = NULL,
+                            progress = NULL,
                             include_header = TRUE,
                             batch_size = 1024L) {
+
+  passed_args <- as.list(match.call()[-1])
+
+  arrow_write_opts <- names(formals(CsvWriteOptions$create))
+  write_args <- names(formals(write_csv_arrow))
+
+  unsupported_opts <- setdiff(
+    write_args,
+    union(arrow_write_opts, c("x", "sink"))
+  )
+
+  unsupported_passed_args <- names(unlist(passed_args[unsupported_opts]))
+
+  if (length(unsupported_passed_args)) {
+    stop(
+      "The following ",
+      ngettext(length(unsupported_passed_args), "argument is ", "arguments are 
"),
+      "not yet supported in Arrow: ",
+      oxford_paste(unsupported_passed_args),
+      call. = FALSE
+    )
+  }

Review comment:
       Yeah, I like this approach proposed by @paleolimbot here. It should also 
avoid any need for parsing the formals and comparing those.
   
   You can also make a helper function for that [like we do with the reading 
side](readr_to_csv_parse_options)




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