| <!--- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| # 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. |
| |
| ### Solution |
| |
| ```{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. |
| |
| ### Solution |
| |
| ```{r, pyarrow_func} |
| table_1 <- arrow_table(mtcars[1:5,]) |
| table_2 <- arrow_table(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(arrow_table(mtcars[c(1:5,11:15),])) |
| ) |
| }) |
| ``` |
| |