Skip to content

[R] Update write_csv_arrow() implementation to match readr::write_csv() #36864

Open

Description

@thisisnic

Describe the enhancement requested

The implementation of arrow::read_csv_arrow() intentionally mirrors readr::read_csv. However, the implementation of arrow::write_csv_arrow() doesn't closely mirror readr::write_csv().

Now that we have additional convenience functions for write_dataset() being implemented in #36436, this presents a problem in that the open_dataset() convenience wrapper functions use the parameters from the read_* functions to provide a common interface which also reflect the readr interface. However, at present, if we implement the write_*_dataset() to mirror the write_csv_arrow() interface, this will provide an inconsistent interface - different to the readr API we're trying to emulate.

We could rewrite the interface for write_csv_arrow() to map more closely to readr::write_csv() to enable these other changes. However, this would constitute a breaking change. It's unclear how much user impact this would have.

Changes needed to be made to write_csv_arrow():

  • expose additional options available through CsvWriteOptions:
    • quoting_style
    • eol
    • delimiter
  • add parameter quote to write_csv_arrow()
  • collapse parameters sink and file into a single parameter (by checking the type of the object passed in and changing behavior accordingly)
  • collapse parameters include_header and col_names into a single parameter (col_names)
  • removing the batch_size param (which should be specified in write_options
  • updating the default value of the na param to match readr::write_csv
  • adding parameter eol which is mapped to that option
  • potentially open an issue requesting the option to specify escape ("The type of escape to use when quotes are in the data") OR just not implementing this parameter OR implement it and set the default to whatever Arrow does by default and raise an error if the user specifies an alternative value

Component(s)

R

Activity

  1. danepitkin commented on Jul 25, 2023

    @danepitkin
    Member

    It would be nice to keep the the readr support for write APIs if its already done for the read APIs. However, is it possible to do this without introducing a breaking change? From the user's perspective, it would be great to have the current API supported, but marked deprecated, when the new API definition is introduced. Is there an easy way to do function overloading in R? If we have to have a single function definition with multiple parameter options for the different "versions" of the API, we should document which parameters are deprecated and let the non-deprecated equivalent options always take precedence. I'm not sure how complicated this code would be, but if it's manageable we can always delete the deprecated code in a later release.

    Long term, I'm not sure how valuable it is to tie our interfaces to another package's interfaces. This can be great for package adoption early on, but if the Arrow package is successful on its own it can be better for both the user and maintainer to have an interface optimized for the implementation. You'll sometimes see packages start with an interface that mimics another piece of software's interface, but once popular they implement their own. It all depends on what is the biggest hurdle for your users e.g. getting started vs usability.

  2. thisisnic commented on Jul 25, 2023

    @thisisnic
    MemberAuthor

    Good shout re deprecation; this might be a nicer way to remove those duplicated parameters slowly.

    A lot of the Arrow package design is based around predominant APIs used widely in R on the premise that you can use your existing data pipelines on bigger data with little change to your existing code, and without having to learn a whole new API. These are well-designed and popular APIs, and IMO is part of the appeal of the package. Moving away from this would involve creating a whole new API altogether, which doesn't feel like would be a good investment of time/effort.

    That said, we are in this middle ground of supporting both those and the wider Arrow functionality. We achieve this through exporting Arrow objects as R6 classes so "advanced" users can work in a way which is closer to the Arrow C++ implementation where needed, to some extent. I've recently been updating our docs to better segregate these approaches, but we could probably do more here in terms of documentation.

  3. danepitkin commented on Jul 25, 2023

    @danepitkin
    Member

    Ah makes sense! If this API design pattern is common across the R ecosystem, then let's definitely try to support it. I don't think this is quite as common in other languages which is why I mentioned it.

  4. thisisnic commented on Jul 25, 2023

    @thisisnic
    MemberAuthor

    Well, it's not necessarily common as such, but a deliberate design choice with the arrow R package specifically. Thanks again, good to get some perspectives from folks who aren't as close to the specific codebase!

  5. paleolimbot commented on Jul 25, 2023

    @paleolimbot
    Member

    There is certainly a lot of precedent in the Arrow package for providing drop-in interfaces for other tidyverse packages. I don't happen to think this is a good idea for many of the points that Dane mentioned. Notably, it creates maintenance work by requiring that our interface keep up with the interface defined elsewhere (or introduces potential bugs in user code that relies on the expectation that everything "just works" when we do not necessarily test every possible combination).

    I would favour future design decisions that center around what Arrow C++ provides and how it provides it. This is the approach that pyarrow takes and has the advantage that many C++ PRs also update pyarrow because the relationship between the two is so straightfoward. Packages that depend on pyarrow (e.g., pandas 2.0, duckdb) take on the responsibility of providing its features (and associated maintenance responsibility of keeping the implementations in sync) in a more user-facing form. My ideal world would be a world where the arrow R package wraps Arrow C++ and tidyverse compatibility lives in another package where it can focus on doing that one thing well; however, I am not aware of any other arrow R developer who shares that opinion.

    On write_csv_arrow() specifically...I am neither for nor against the compatability with readr: I don't consider it something I would spend time doing; however, if somebody else finds it a useful exercise and it can be done well, I don't think that CSV writing specifically is likely to change at a pace that we can't maintain.

  6. thisisnic commented on Jul 26, 2023

    @thisisnic
    MemberAuthor

    @paleolimbot I see where you're coming from with regards to potential high-level design decisions, but I'd be curious to know what you think we should do in #36436 if we don't make this update?

  7. thisisnic commented on Jul 27, 2023

    @thisisnic
    MemberAuthor

    This was discussed in the Arrow R package dev community discussion today. The general ideas discussed were the fact that convenience wrappers are important in principle to make it easier to document our functions more simply as well as ease of use, soft deprecation would help with the issue of making a breaking change, but also that to change write_csv_arrow() for the sake of writing a good wrapper for the write_*_dataset() functions is extra work.

    Given my speculation that the individual write function ( write_csv_arrow()) isn't widely used, it follows that we could implement the new write_*_dataset() wrappers to reflect the readr::write_csv parameter names (similarly to open_*_dataset() and come back to potentially updating write_csv_arrow() if there's community interest or more compelling reasons to do so later.

    I agree with your points about the maintenance burden @paleolimbot , and I think a middle ground here would be to finish off any partial implementations we've made but not necessarily make new changes without good reason (i.e. it makes sense to have write_*_dataset() to mirror open_*_dataset() as we've already done the latter, but no need to rewrite write_csv_arrow() just for the sake of it), increase our rigour around testing (there have been clear gaps in the past), and where we feel wrappers are necessary then create thin wrappers which don't do additional work (i.e. like the thin wrappers in #36851) and instead favour requesting upstream fixes/changes in the C++ library or documenting any peculiarities instead of coding around them.

  8. paleolimbot commented on Aug 9, 2023

    @paleolimbot
    Member

    Thank you for bringing this up an navigating the conversation!

    I think a middle ground here would be to finish off any partial implementations we've made but not necessarily make new changes without good reason

    That sounds like great middle ground!

    instead favour requesting upstream fixes/changes in the C++ library or documenting any peculiarities instead of coding around them.

    Agreed!

  9. added
    Status: stale-warning
    on Feb 18, 2026
  10. thisisnic commented on Feb 18, 2026

    @thisisnic
    MemberAuthor

    This issue has been marked as stale because it has had no activity in the past 2 years. Please remove the stale label or comment below, or this issue will be closed in 14 days.

  11. removed
    Status: stale-warning
    on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions