rdata

raw JSON →
1.0.0 verified Mon Apr 27 auth: no python

A Python library to read R datasets (.rda, .rdata) into Python objects. Version 1.0.0, stable release, low cadence.

pip install rdata
error TypeError: expected str, bytes or os.PathLike object, not bytes
cause Passing a path string directly to read_rda instead of a file object.
fix
Use open('file.rda', 'rb') to create a file object.
error rdata._parser.RDataParserError: invalid file signature
cause File is not a valid .rda file or is corrupted.
fix
Verify the file is an R data file; re-save from R if needed.
breaking Requires Python >=3.11; will fail on older Python versions.
fix Upgrade Python to 3.11 or later.
gotcha read_rda expects a binary file-like object, not a file path. Passing a string path raises TypeError.
fix Open the file with open(path, 'rb') before calling read_rda.
deprecated The function 'read_r' from older versions (pre-0.2) is deprecated; use read_rda instead.
fix Replace read_r with read_rda and adjust argument order.

Open an .rda file in binary mode and parse with read_rda. Returns a dict of R objects.

from rdata import read_rda
import os

# Replace with your .rda file path
file_path = os.environ.get('RDATA_FILE', 'data.rda')
with open(file_path, 'rb') as f:
    data = read_rda(f)
print(data)