dragosmg commented on a change in pull request #11432:
URL: https://github.com/apache/arrow/pull/11432#discussion_r729794177



##########
File path: r/tests/testthat/test-csv.R
##########
@@ -266,6 +266,26 @@ test_that("Mix of guessing and declaring types", {
   expect_identical(df, tbl[, c("dbl", "false", "chr")])
 })
 
+test_that("more informative error when reading a CSV with headers and schema", 
{
+  tf <- tempfile()
+  on.exit(unlink(tf))
+  share_data <- tibble::tibble(

Review comment:
       Done.

##########
File path: r/tests/testthat/test-csv.R
##########
@@ -266,6 +266,26 @@ test_that("Mix of guessing and declaring types", {
   expect_identical(df, tbl[, c("dbl", "false", "chr")])
 })
 
+test_that("more informative error when reading a CSV with headers and schema", 
{
+  tf <- tempfile()
+  on.exit(unlink(tf))
+  share_data <- tibble::tibble(
+    company = c("AMZN", "GOOG", "BKNG", "TSLA"),
+    price = c(3463.12, 2884.38, 2300.46, 732.39)
+  )
+
+  readr::write_csv(share_data, tf)

Review comment:
       True. I've swapped `read::write_csv()` for `base::write.csv()`.

##########
File path: r/R/util.R
##########
@@ -193,3 +193,16 @@ repeat_value_as_array <- function(object, n) {
   }
   return(Scalar$create(object)$as_array(n))
 }
+
+handle_csv_read_error <- function(e, schema) {
+  msg <- conditionMessage(e)
+
+  if (grepl("conversion error", msg) && inherits(schema, "Schema")) {
+    abort(c(
+      msg,
+      i = "Did you check your CSV file doesn't have a header row?"

Review comment:
       I think it's difficult to pinpoint the error and give a precise 
suggestion. We could add an advice to try `skip = 1`, but this assumes the 
header row is the first one, etc.




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