Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
ARROW-13714: [Doc][Cookbook] Sharing data between R and Python - R (#99)
* Initial file * Add to bookdown file * Add examples * Add example of PyArrow functions * Initial file * Add to bookdown * Add examples * Add example of PyArrow functions * Capitalisation * Update dependencies * Add pyarrow installation * Consistent capitalisation
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -40,6 +40,7 @@ ifdef arrow_r_version | ||
else | ||
cd ./r && Rscript ./scripts/install_dependencies.R | ||
endif | ||
pip install pyarrow | ||
|
||
|
||
r: rdeps | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,5 +12,6 @@ rmd_files: [ | ||
"specify_data_types_and_schemas.Rmd", | ||
"arrays.Rmd", | ||
"tables.Rmd", | ||
"python.Rmd", | ||
"flight.Rmd" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Using PyArrow from R | ||
|
||
## Introduction | ||
|
||
For more information on using setting up and installing PyArrow to use in R, see | ||
[the "Apache Arrow in Python and R with reticulate" vignette](https://arrow.apache.org/docs/r/articles/python.html). | ||
|
||
## Create an Arrow object using PyArrow in R | ||
|
||
You want to use PyArrow to create an Arrow object in an R session. | ||
|
||
```{r, pyarrow_object} | ||
library(reticulate) | ||
pa <- import("pyarrow") | ||
pyarrow_scalar <- pa$scalar(42) | ||
pyarrow_scalar | ||
``` | ||
```{r, test_pyarrow_object, opts.label = "test"} | ||
test_that("pyarrow_object", { | ||
expect_s3_class(pyarrow_scalar, "pyarrow.lib.Scalar") | ||
}) | ||
``` | ||
|
||
## Call a PyArrow function from R | ||
|
||
You want to call a PyArrow function from your R session. | ||
|
||
```{r, pyarrow_func} | ||
table_1 <- Table$create(mtcars[1:5,]) | ||
table_2 <- Table$create(mtcars[11:15,]) | ||
pa$concat_tables(tables = list(table_1, table_2)) %>% | ||
collect() | ||
``` | ||
```{r, test_pyarrow_func, opts.label="test"} | ||
test_that("pyarrow_func", { | ||
expect_equal( | ||
collect(pa$concat_tables(tables = list(table_1, table_2))), | ||
collect(Table$create(mtcars[c(1:5,11:15),])) | ||
) | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters