parse_file#
- parse_file(file_or_path, *, expand_altrep=True, altrep_constructor_dict=DEFAULT_ALTREP_MAP, extension=None)[source]#
Parse a R file (.rda or .rdata).
- Parameters:
file_or_path (AcceptableFile | os.PathLike[Any] | Traversable | str) – File in the R serialization format.
expand_altrep (bool) – Whether to translate ALTREPs to normal objects.
altrep_constructor_dict (AltRepConstructorMap) – Dictionary mapping each ALTREP to its constructor.
extension (str | None) – Extension of the file.
- Returns:
Data contained in the file (versions and object).
- Return type:
RData
See also
parse_data()
: Similar function that receives the data directly.Examples
Parse one of the included examples, containing a vector
>>> import rdata >>> >>> parsed = rdata.parser.parse_file( ... rdata.TESTDATA_PATH / "test_vector.rda") >>> parsed RData(versions=RVersions(format=2, serialized=196610, minimum=131840), extra=RExtraInfo(encoding=None), object=RObject(info=RObjectInfo(type=<RObjectType.LIST: 2>, object=False, attributes=False, tag=True, gp=0, reference=0), value=(RObject(info=RObjectInfo(type=<RObjectType.REAL: 14>, object=False, attributes=False, tag=False, gp=0, reference=0), value=array([1., 2., 3.]), attributes=None, tag=None, referenced_object=None), RObject(info=RObjectInfo(type=<RObjectType.NILVALUE: 254>, object=False, attributes=False, tag=False, gp=0, reference=0), value=None, attributes=None, tag=None, referenced_object=None)), attributes=None, tag=RObject(info=RObjectInfo(type=<RObjectType.SYM: 1>, object=False, attributes=False, tag=False, gp=0, reference=0), value=RObject(info=RObjectInfo(type=<RObjectType.CHAR: 9>, object=False, attributes=False, tag=False, gp=64, reference=0), value=b'test_vector', attributes=None, tag=None, referenced_object=None), attributes=None, tag=None, referenced_object=None), referenced_object=None))