Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/machow/wrestlr
Why debate R vs python, when you can convert R to python?
https://github.com/machow/wrestlr
Last synced: 3 months ago
JSON representation
Why debate R vs python, when you can convert R to python?
- Host: GitHub
- URL: https://github.com/machow/wrestlr
- Owner: machow
- Created: 2020-04-23T16:49:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-24T14:41:47.000Z (over 4 years ago)
- Last Synced: 2024-04-26T20:46:58.120Z (8 months ago)
- Language: Python
- Homepage:
- Size: 145 KB
- Stars: 18
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
# wrestlr
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/machow/wrestlr/master)
The language wars are over.
wrestlr uses python to do a two step dance:
* parse R code that uses [dplyr](https://github.com/tidyverse/dplyr).
* spit out python code that runs using the dplyr port [siuba](http://github.com/machow/siuba).## Basic use
```{python}
import wrestlrr_code = """
mtcars %>%
filter(hp < 200)
"""wrestlr.rlang_convert(r_code)
```It's much nicer to use IPython cell magic, though!
```{python}
import wrestlr
# %load_ext wrestlr
``````{python}
# %%wrestlr --print
1'a'
TRUE
NULL
x$y
x[["y"]]
```Here is another example with ggplot.
```{python}
# %%wrestlr --print
mtcars %>%
select(hp, mpg, cyl) %>%
ggplot(aes(hp, mpg)) +
geom_point() +
facet_wrap(~cyl)
```## Executing
Instead of printing code, you can execute it using the `--execute` option. First, we'll import some python functions.
```{python}
# import wrestlr
# # %load_ext wrestlrimport pandas as pd
from siuba import _, mutate, group_by, ungroup
from siuba.data import mtcarsfrom plotnine import *
def factor(x):
return pd.Categorical(x)
```Next we convert and execute the code.
```{python}
# %%wrestlr --print --execute --blackmtcars %>%
group_by(cyl) %>%
mutate(demeaned_mpg = mpg - mean(mpg)) %>%
ungroup() %>%
ggplot(aes(factor(cyl), demeaned_mpg)) +
geom_boxplot()```
## Learning more
See these example notebooks
| name | binder | description |
| ---- | ------ | ----------- |
| [gallery](docs/gallery.ipynb) | [![](https://mybinder.org/badge_logo.svg)][b-gallery] | Walk through rules wrestlr uses during conversion |
| [cell_magic](docs/cell_magic.ipynb) | [![](https://mybinder.org/badge_logo.svg)][b-cell-magic] | Get to know the %%wrestlr cell magic |
| [debugging.ipynb](docs/debugging.ipynb) | [![](https://mybinder.org/badge_logo.svg)][b-debugging] | Debugging the parser, AST, or siuba conversion |
| [translate-tidytuesday](docs/translate-tidytuesday.ipynb) | [![](https://mybinder.org/badge_logo.svg)][b-translate-tidytuesday] | Translating and executing the first half of a tidy tuesday R analysis |[b-gallery]: https://mybinder.org/v2/gh/machow/wrestlr/master?filepath=docs/gallery.ipynb
[b-cell-magic]: https://mybinder.org/v2/gh/machow/wrestlr/master?filepath=docs/cell_magic.ipynb
[b-debugging]: https://mybinder.org/v2/gh/machow/wrestlr/master?filepath=docs/debugging.ipynb
[b-translate-tidytuesday]: https://mybinder.org/v2/gh/machow/wrestlr/master?filepath=docs/translate-tidytuesday.ipynb