ENH: IO support for R data files with C extension
State: closed

- [X] follows up on #40884
- [X] tests added / passed
- [X] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them
- [X] whatsnew entry
- [X] user_guide/io entry




### Proposed RData I/O module interfaces to the C library: [librdata](https://github.com/WizardMac/librdata). 

Overall, this PR includes following changes:
- **setup.py**: pandas/setup.py (new rdata section at the bottom)
- **librdata**: pandas/_libs/src/librdata (C and header files and iconv scripts)
- **rdata IO**: pandas/io/rdata (Cython and Python scripts)
- **frame.py**: pandas/core/frame.py (for `DataFrame.to_rdata`)
- **tests**: pandas/tests/io/test_rdata.py
- **tests data**: pandas/tests/io/data/rdata (R data files in gzip compression)
- **docs**: librdata license, user_guide/io.rst, whatsnew/v1.3.0.rst

Note: special handling of `iconv`, a system resource built-in to Unix machines, is required:
- For Linux, to centralize from different locations, the `iconv.h` header of the GNU C library is included.
- For Mac, setup.py points to system folders, `/usr/include` and `/usr/lib`, which may differ from users installs.
- For Windows , since `iconv` is not built-in, two counterpart files (.h and .c script) were added from this repo, [win-iconv](https://github.com/win-iconv/win-iconv), where its readme indicates code is placed in the public domain.

Labels:
name: Enhancement
name: IO Data
description: IO issues that don't fit into a more specific label
name: Stale

Comments:
@jreback, @bashtage - What are your thoughts of this C extension? Biggest challenge was handling `iconv` across OSes.
@jreback - These binary formats (RData, rda, rds) are part of `base` R (or the standard library of R) as native serialization types. Methods to create them ship with every installation of R. The R Core Team maintain these types. AFAIK, while the `arrow` package of R and `pyarrow` of Python can read text files like csv and json and compress to gz and bzip2 types, they do not read or write to these R data formats. From what I see, the only binary types Arrow supports are `parquet` and `feather`. And from McKinney and Wickham blogs, I believe these formats serve as alternatives for their speed in read/write and language-independent interoperability.
What is the status here? I see no further response. I can rebase but this ENH may not make it into v1.3. I fully understand that this PR with new C extension is pretty involved and we want to be conservative on large enhancements in `pandas` code base.
@ParfaitG have been busy but will take a look
If you recall, we explored a Python package for this IO module to read R data files but it had a restrictive license. See previous PR in my first checked item at top. That package was a wrapper to this same C library that we directly interfaced with here, avoiding another soft dependency for pandas.

Regarding size, this [librdata](https://github.com/WizardMac/librdata) proclaims itself as a small, lightweight C library. Its source files with two added scripts for Windows totals 177 KB (slightly larger than `ujson` at 175 KB). Also, the *only* compiled Cython `_rdata` module totals 186 KB for Python 3.9 on Linux, likely about the same for Py 3.7/3.8. By comparison, SAS's compiled Cython module totals 256 KB. Corresponding `_rdata.c` comes to 533 KB (with SAS's _sas.c at 1.0 MB).


This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.