{"id":15564854,"url":"https://github.com/vnmabus/rdata","last_synced_at":"2025-04-05T08:07:54.100Z","repository":{"id":32841765,"uuid":"139425083","full_name":"vnmabus/rdata","owner":"vnmabus","description":"Reader of R datasets in .rda format, in Python","archived":false,"fork":false,"pushed_at":"2025-03-12T10:41:31.000Z","size":884,"stargazers_count":52,"open_issues_count":5,"forks_count":3,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-03-29T07:07:20.000Z","etag":null,"topics":["conversion","python","python3","r","rda","rdata","rds"],"latest_commit_sha":null,"homepage":"https://rdata.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vnmabus.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-02T10:00:50.000Z","updated_at":"2025-03-12T10:41:35.000Z","dependencies_parsed_at":"2022-08-28T13:52:57.699Z","dependency_job_id":"cfc97200-c6f4-4d9d-9d7f-7a02db884db9","html_url":"https://github.com/vnmabus/rdata","commit_stats":{"total_commits":111,"total_committers":2,"mean_commits":55.5,"dds":0.009009009009009028,"last_synced_commit":"bae7eb8f005307996880f99437257bd41bd7c9df"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnmabus%2Frdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnmabus%2Frdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnmabus%2Frdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vnmabus%2Frdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vnmabus","download_url":"https://codeload.github.com/vnmabus/rdata/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305934,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conversion","python","python3","r","rda","rdata","rds"],"created_at":"2024-10-02T16:43:41.068Z","updated_at":"2025-04-05T08:07:54.081Z","avatar_url":"https://github.com/vnmabus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"rdata\n=====\n\n|build-status| |docs| |coverage| |repostatus| |versions| |pypi| |conda| |zenodo| |pyOpenSci| |joss|\n\nA Python library for R datasets.\n\n..\n\tGithub does not support include in README for dubious security reasons, so\n\twe copy-paste instead. Also Github does not understand Sphinx directives.\n\t.. include:: docs/index.rst\n\t.. include:: docs/simpleusage.rst\n\nThe package rdata offers a lightweight way to import R datasets/objects stored\nin the \".rda\" and \".rds\" formats into Python.\nIts main advantages are:\n\n- It is a pure Python implementation, with no dependencies on the R language or\n  related libraries.\n  Thus, it can be used anywhere where Python is supported, including the web\n  using `Pyodide \u003chttps://pyodide.org/\u003e`__.\n- It attempt to support all R objects that can be meaningfully translated.\n  As opposed to other solutions, you are no limited to import dataframes or\n  data with a particular structure.\n- It allows users to easily customize the conversion of R classes to Python\n  ones.\n  Does your data use custom R classes?\n  Worry no longer, as it is possible to define custom conversions to the Python\n  classes of your choosing.\n- It has a permissive license (MIT). As opposed to other packages that depend\n  on R libraries and thus need to adhere to the GPL license, you can use rdata\n  as a dependency on MIT, BSD or even closed source projects.\n\t\nInstallation\n============\n\nrdata is on PyPi and can be installed using :code:`pip`:\n\n.. code::\n\n   pip install rdata\n\nIt is also available for :code:`conda` using the :code:`conda-forge` channel:\n\n.. code::\n\n   conda install -c conda-forge rdata\n   \nInstalling the develop version\n------------------------------\n\nThe current version from the develop branch can be installed as\n\n.. code::\n\n   pip install git+https://github.com/vnmabus/rdata.git@develop\n\nDocumentation\n=============\n\nThe documentation of rdata is in\n`ReadTheDocs \u003chttps://rdata.readthedocs.io/\u003e`__.\n\nExamples\n========\n\nExamples of use are available in\n`ReadTheDocs \u003chttps://rdata.readthedocs.io/en/stable/auto_examples/\u003e`__.\n\nCiting rdata\n============\n\nPlease, if you find this software useful in your work, reference it citing the following paper:\n\n.. code-block::\n\n  @article{ramos-carreno+rossi_2024_rdata,\n      author = {Ramos-Carreño, Carlos and Rossi, Tuomas},\n      doi = {10.21105/joss.07540},\n      journal = {Journal of Open Source Software},\n      month = dec,\n      number = {104},\n      pages = {1--4},\n      title = {{rdata: A Python library for R datasets}},\n      url = {https://joss.theoj.org/papers/10.21105/joss.07540#},\n      volume = {9},\n      year = {2024}\n  }\n\nYou can additionally cite the software repository itself using:\n\n.. code-block::\n\n  @misc{ramos-carreno++_2024_rdata-repo,\n    author = {The rdata developers},\n    doi = {10.5281/zenodo.6382237},\n    month = dec,\n    title = {rdata: A Python library for R datasets},\n    url = {https://github.com/vnmabus/rdata},\n    year = {2024}\n  }\n\nIf you want to reference a particular version for reproducibility, check the version-specific DOIs available in Zenodo.\n\t\nSimple usage\n============\n\nRead a R dataset\n----------------\n\nThe common way of reading an R dataset is the following one:\n\n.. code:: python\n\n    import rdata\n\n    converted = rdata.read_rda(rdata.TESTDATA_PATH / \"test_vector.rda\")\n    converted\n    \nwhich results in\n\n.. code::\n\n    {'test_vector': array([1., 2., 3.])}\n\nUnder the hood, this is equivalent to the following code:\n\n.. code:: python\n\n    import rdata\n\n    parsed = rdata.parser.parse_file(rdata.TESTDATA_PATH / \"test_vector.rda\")\n    converted = rdata.conversion.convert(parsed)\n    converted\n    \nThis consists on two steps: \n\n#. First, the file is parsed using the function\n   `rdata.parser.parse_file \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.parser.parse_file.html\u003e`__.\n   This provides a literal description of the\n   file contents as a hierarchy of Python objects representing the basic R\n   objects. This step is unambiguous and always the same.\n#. Then, each object must be converted to an appropriate Python object. In this\n   step there are several choices on which Python type is the most appropriate\n   as the conversion for a given R object. Thus, we provide a default\n   `rdata.conversion.convert \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.convert.html\u003e`__\n   routine, which tries to select Python objects that preserve most information\n   of the original R object. For custom R classes, it is also possible to\n   specify conversion routines to Python objects.\n   \nConvert custom R classes\n------------------------\n\nThe basic\n`convert \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.convert.html\u003e`__\nroutine only constructs a\n`SimpleConverter \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.SimpleConverter.html\u003e`__\nobject and calls its\n`convert \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.SimpleConverter.html#rdata.conversion.SimpleConverter.convert\u003e`__\nmethod. All arguments of\n`convert \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.convert.html\u003e`__\nare directly passed to the\n`SimpleConverter \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.SimpleConverter.html\u003e`__\ninitialization method.\n\nIt is possible, although not trivial, to make a custom\n`Converter \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.Converter.html\u003e`__\nobject to change the way in which the\nbasic R objects are transformed to Python objects. However, a more common\nsituation is that one does not want to change how basic R objects are\nconverted, but instead wants to provide conversions for specific R classes.\nThis can be done by passing a dictionary to the\n`SimpleConverter \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.SimpleConverter.html\u003e`__\ninitialization method, containing\nas keys the names of R classes and as values, callables that convert a\nR object of that class to a Python object. By default, the dictionary used\nis\n`DEFAULT_CLASS_MAP \u003chttps://rdata.readthedocs.io/en/latest/modules/rdata.conversion.DEFAULT_CLASS_MAP.html\u003e`__,\nwhich can convert commonly used R classes such as\n`data.frame \u003chttps://www.rdocumentation.org/packages/base/topics/data.frame\u003e`__\nand `factor \u003chttps://www.rdocumentation.org/packages/base/topics/factor\u003e`__.\n\nAs an example, here is how we would implement a conversion routine for the\nfactor class to\n`bytes \u003chttps://docs.python.org/3/library/stdtypes.html#bytes\u003e`__\nobjects, instead of the default conversion to\nPandas\n`Categorical \u003chttps://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Categorical.html#pandas.Categorical\u003e`__ objects:\n\n.. code:: python\n\n    import rdata\n\n    def factor_constructor(obj, attrs):\n        values = [bytes(attrs['levels'][i - 1], 'utf8')\n                  if i \u003e= 0 else None for i in obj]\n   \n        return values\n\n    new_dict = {\n        **rdata.conversion.DEFAULT_CLASS_MAP,\n        \"factor\": factor_constructor\n    }\n\n    converted = rdata.read_rda(\n        rdata.TESTDATA_PATH / \"test_dataframe.rda\",\n        constructor_dict=new_dict,\n    )\n    converted\n    \nwhich has the following result:\n\n.. code::\n\n    {'test_dataframe':   class  value\n        1     b'a'      1\n        2     b'b'      2\n        3     b'b'      3}\n    \nAdditional examples\n===================\n\nAdditional examples illustrating the functionalities of this package can be\nfound in the\n`ReadTheDocs documentation \u003chttps://rdata.readthedocs.io/en/latest/auto_examples/index.html\u003e`__.\n\n\n.. |build-status| image:: https://github.com/vnmabus/rdata/actions/workflows/main.yml/badge.svg?branch=master\n    :alt: build status\n    :target: https://github.com/vnmabus/rdata/actions/workflows/main.yml\n\n.. |docs| image:: https://readthedocs.org/projects/rdata/badge/?version=latest\n    :alt: Documentation Status\n    :target: https://rdata.readthedocs.io/en/latest/?badge=latest\n    \n.. |coverage| image:: http://codecov.io/github/vnmabus/rdata/coverage.svg?branch=develop\n    :alt: Coverage Status\n    :target: https://codecov.io/gh/vnmabus/rdata/branch/develop\n\n.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg\n   :alt: Project Status: Active – The project has reached a stable, usable state and is being actively developed.\n   :target: https://www.repostatus.org/#active\n\n.. |versions| image:: https://img.shields.io/pypi/pyversions/rdata\n   :alt: PyPI - Python Version\n    \n.. |pypi| image:: https://badge.fury.io/py/rdata.svg\n    :alt: Pypi version\n    :target: https://pypi.python.org/pypi/rdata/\n\n.. |conda| image:: https://anaconda.org/conda-forge/rdata/badges/version.svg\n    :alt: Conda version\n    :target: https://anaconda.org/conda-forge/rdata\n\n.. |zenodo| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.6382237.svg\n    :alt: Zenodo DOI\n    :target: https://doi.org/10.5281/zenodo.6382237\n    \n.. |pyOpenSci| image:: https://tinyurl.com/y22nb8up\n    :alt: pyOpenSci: Peer reviewed\n    :target: https://github.com/pyOpenSci/software-submission/issues/144\n\n.. |joss| image:: https://joss.theoj.org/papers/10.21105/joss.07540/status.svg\n   :target: https://doi.org/10.21105/joss.07540\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnmabus%2Frdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvnmabus%2Frdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvnmabus%2Frdata/lists"}