Skip to main content

Python package for using R in Python

Project description

RWrapR

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

Features

RWrapR is a python package for using R inside of python. It is built using rpy2, but attempts to be more convient to use. Ideally you should never have to worry about using R objects, instead treating R functions as normal python functions, where the inputs and outputs are python objects.

import rwrapr as wr
import pandas as pd
import numpy as np

dplyr = wr.library("dplyr")
dt = wr.library("datasets")

dplyr.last(x=np.array([1, 2, 3, 4]))
dplyr.last(x=[1, 2, 3, 4])

iris = dt.iris
df = dplyr.mutate(iris, Sepal=wr.Lazily("round(Sepal.Length * 2, 0)"))

To do

1. Better warning handling (this will likely be tricky)
    - Sometimes we will get datatypes which are incompatible,
        e.g., warning accompanied by
2. Better handling of missing values.

Requirements

  • R must be installed

Installation

You can install RWrapR via pip from PyPI:

pip install rwrapr

Usage

Please see the Reference Guide for details.

Managing R dependencies

RWrapR will automatically install the required R packages, using the global library path. Sometimes this is not desirable, and you may want to use the renv package to manage your R dependencies. To do this, you can use renv via the rwrapr package.

import rwrapr as wr

renv = wr.library("renv") # note you must install renv globally first
renv.init() # initialize renv

renv.install("statisticsnorway/ssb-metodebiblioteket")
renv.install("metodebiblioteket")

renv.snapshot(type="all") # update lock-file

If you are using .ipynb files, you can should add renv.autoload() to the top of your notebook to ensure that the correct R environment is loaded.

For further details, see the Renv Article

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, RWrapR is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rwrapr-0.9.3.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rwrapr-0.9.3-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file rwrapr-0.9.3.tar.gz.

File metadata

  • Download URL: rwrapr-0.9.3.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rwrapr-0.9.3.tar.gz
Algorithm Hash digest
SHA256 96496f311f41e3d0abda8b77553caf2a9d767c4b3cac85acf369c41bc433d2e6
MD5 2f5820c1d5adbce65e0cb6612c547818
BLAKE2b-256 bd51109c3c9fba16e4d8664b5f5bc26f432e01e8931c55ec5fa7e2146cd256b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rwrapr-0.9.3.tar.gz:

Publisher: release.yml on statisticsnorway/ssb-rwrapr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rwrapr-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: rwrapr-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rwrapr-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5990e66a987cedc40357ea2ad1886c7c8f6d37fbd82dfd08b6c57810c21c9162
MD5 4b1d9047fc6eb2fefa7903552a8d8a11
BLAKE2b-256 4250b0d4716edc3a853d4fb4090602e8f7a975db25d1d983d4fcb1bf93baf874

See more details on using hashes here.

Provenance

The following attestation bundles were made for rwrapr-0.9.3-py3-none-any.whl:

Publisher: release.yml on statisticsnorway/ssb-rwrapr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page