Metadata-Version: 2.3
Name: rwrapr
Version: 0.9.2
Summary: Python package for using R in Python
License: MIT
Author: Kjell Solem Slupphaug
Author-email: kjell.solem.slupphaug@ssb.no
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: dapla-toolbelt (>=1.3.2)
Requires-Dist: jinja2 (>=3.1.5)
Requires-Dist: numpy (>=1.26.4)
Requires-Dist: pandas (>=2.2.0)
Requires-Dist: rpy2 (>=3.5.16)
Requires-Dist: scipy (>=1.3)
Requires-Dist: termcolor (>=2.4.0)
Project-URL: Changelog, https://github.com/statisticsnorway/ssb-rwrapr/releases
Project-URL: Documentation, https://statisticsnorway.github.io/ssb-rwrapr
Project-URL: Homepage, https://github.com/statisticsnorway/ssb-rwrapr
Project-URL: Repository, https://github.com/statisticsnorway/ssb-rwrapr
Description-Content-Type: text/markdown

# RWrapR

[![PyPI](https://img.shields.io/pypi/v/rwrapr.svg)][pypi status]
[![Status](https://img.shields.io/pypi/status/rwrapr.svg)][pypi status]
[![Python Version](https://img.shields.io/pypi/pyversions/rwrapr)][pypi status]
[![License](https://img.shields.io/pypi/l/rwrapr)][license]

[![Documentation](https://github.com/statisticsnorway/ssb-rwrapr/actions/workflows/docs.yml/badge.svg)][documentation]
[![Tests](https://github.com/statisticsnorway/ssb-rwrapr/actions/workflows/tests.yml/badge.svg)][tests]
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-rwrapr&metric=coverage)][sonarcov]
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=statisticsnorway_ssb-rwrapr&metric=alert_status)][sonarquality]

[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)][pre-commit]
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black]
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)][poetry]

[pypi status]: https://pypi.org/project/ssb-rwrapr/
[documentation]: https://statisticsnorway.github.io/ssb-rwrapr
[tests]: https://github.com/statisticsnorway/ssb-rwrapr/actions?workflow=Tests

[sonarcov]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-rwrapr
[sonarquality]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-rwrapr
[pre-commit]: https://github.com/pre-commit/pre-commit
[black]: https://github.com/psf/black
[poetry]: https://python-poetry.org/

## Features <img src="images/WrapR-logo.png" alt="Logo" align = "right" height="139" class="logo">
`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.

```python
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]:

```console
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.

```python
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](RENV.md)

## Contributing

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

## License

Distributed under the terms of the [MIT license][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].

[statistics norway]: https://www.ssb.no/en
[pypi]: https://pypi.org/
[ssb pypi template]: https://github.com/statisticsnorway/ssb-pypitemplate
[file an issue]: https://github.com/statisticsnorway/ssb-rwrapr/issues
[pip]: https://pip.pypa.io/

<!-- github-only -->

[license]: https://github.com/statisticsnorway/ssb-rwrapr/blob/main/LICENSE
[contributor guide]: https://github.com/statisticsnorway/ssb-rwrapr/blob/main/CONTRIBUTING.md
[reference guide]: https://statisticsnorway.github.io/ssb-rwrapr/reference.html

