You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2020/04/08 08:48:02 UTC

[arrow] branch master updated: ARROW-8352: [R] Add install_pyarrow()

This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new cfc7f3a  ARROW-8352: [R] Add install_pyarrow()
cfc7f3a is described below

commit cfc7f3a812554f6ffe03ce27a813091a51831071
Author: Neal Richardson <ne...@gmail.com>
AuthorDate: Wed Apr 8 10:47:34 2020 +0200

    ARROW-8352: [R] Add install_pyarrow()
    
    Closes #6856 from nealrichardson/install-pyarrow
    
    Authored-by: Neal Richardson <ne...@gmail.com>
    Signed-off-by: Antoine Pitrou <an...@python.org>
---
 r/DESCRIPTION                  |  2 +-
 r/Makefile                     |  2 +-
 r/NAMESPACE                    |  1 +
 r/R/{py-to-r.R => python.R}    | 25 +++++++++++++++++++++++++
 r/man/install_pyarrow.Rd       | 22 ++++++++++++++++++++++
 r/tests/testthat/helper-skip.R |  7 +++++++
 r/tests/testthat/test-python.R | 10 ++++++++++
 r/vignettes/python.Rmd         | 16 +++++++++-------
 8 files changed, 76 insertions(+), 9 deletions(-)

diff --git a/r/DESCRIPTION b/r/DESCRIPTION
index 0c7605b..aef9756 100644
--- a/r/DESCRIPTION
+++ b/r/DESCRIPTION
@@ -79,7 +79,7 @@ Collate:
     'memory-pool.R'
     'message.R'
     'parquet.R'
-    'py-to-r.R'
+    'python.R'
     'record-batch-reader.R'
     'record-batch-writer.R'
     'reexports-bit64.R'
diff --git a/r/Makefile b/r/Makefile
index 3413f56..9fe95ad 100644
--- a/r/Makefile
+++ b/r/Makefile
@@ -24,7 +24,7 @@ doc:
 
 test:
 	export ARROW_R_DEV=$(ARROW_R_DEV) && R CMD INSTALL --install-tests --no-test-load --no-docs --no-help --no-byte-compile .
-	export NOT_CRAN=true && R --slave -e 'library(testthat); setwd(file.path(.libPaths()[1], "arrow", "tests")); system.time(test_check("arrow", filter="${file}", reporter=ifelse(nchar("${r}"), "${r}", "summary")))'
+	export NOT_CRAN=true && export ARROW_R_DEV=$(ARROW_R_DEV) && R --slave -e 'library(testthat); setwd(file.path(.libPaths()[1], "arrow", "tests")); system.time(test_check("arrow", filter="${file}", reporter=ifelse(nchar("${r}"), "${r}", "summary")))'
 
 deps:
 	R --slave -e 'lib <- Sys.getenv("R_LIB", .libPaths()[1]); install.packages("devtools", repo="https://cloud.r-project.org", lib=lib); devtools::install_dev_deps(lib=lib)'
diff --git a/r/NAMESPACE b/r/NAMESPACE
index 03fb343..de26a53 100644
--- a/r/NAMESPACE
+++ b/r/NAMESPACE
@@ -154,6 +154,7 @@ export(float64)
 export(halffloat)
 export(hive_partition)
 export(install_arrow)
+export(install_pyarrow)
 export(int16)
 export(int32)
 export(int64)
diff --git a/r/R/py-to-r.R b/r/R/python.R
similarity index 68%
rename from r/R/py-to-r.R
rename to r/R/python.R
index 417a837..4d84a40 100644
--- a/r/R/py-to-r.R
+++ b/r/R/python.R
@@ -64,3 +64,28 @@ r_to_py.RecordBatch <- function(x, convert = FALSE) {
   ExportRecordBatch(x, array_ptr, schema_ptr)
   pa$RecordBatch$`_import_from_c`(array_ptr, schema_ptr)
 }
+
+#' Install pyarrow for use with reticulate
+#'
+#' `pyarrow` is the Python package for Apache Arrow. This function helps with
+#' installing it for use with `reticulate`.
+#'
+#' @param envname The name or full path of the Python environment to install
+#' into. This can be a virtualenv or conda environment created by `reticulate`.
+#' See `reticulate::py_install()`.
+#' @param nightly logical: Should we install a development version of the
+#' package? Default is to use the official release version.
+#' @param ... additional arguments passed to `reticulate::py_install()`.
+#' @export
+install_pyarrow <- function(envname = NULL, nightly = FALSE, ...) {
+  if (nightly) {
+    reticulate::py_install("pyarrow", envname = envname, ...,
+      # Nightly for pip
+      pip_options = "--extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade",
+      # Nightly for conda
+      channel = "arrow-nightlies"
+    )
+  } else {
+    reticulate::py_install("pyarrow", envname = envname, ...)
+  }
+}
diff --git a/r/man/install_pyarrow.Rd b/r/man/install_pyarrow.Rd
new file mode 100644
index 0000000..223a267
--- /dev/null
+++ b/r/man/install_pyarrow.Rd
@@ -0,0 +1,22 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/python.R
+\name{install_pyarrow}
+\alias{install_pyarrow}
+\title{Install pyarrow for use with reticulate}
+\usage{
+install_pyarrow(envname = NULL, nightly = FALSE, ...)
+}
+\arguments{
+\item{envname}{The name or full path of the Python environment to install
+into. This can be a virtualenv or conda environment created by \code{reticulate}.
+See \code{reticulate::py_install()}.}
+
+\item{nightly}{logical: Should we install a development version of the
+package? Default is to use the official release version.}
+
+\item{...}{additional arguments passed to \code{reticulate::py_install()}.}
+}
+\description{
+\code{pyarrow} is the Python package for Apache Arrow. This function helps with
+installing it for use with \code{reticulate}.
+}
diff --git a/r/tests/testthat/helper-skip.R b/r/tests/testthat/helper-skip.R
index d6489fb..2026021 100644
--- a/r/tests/testthat/helper-skip.R
+++ b/r/tests/testthat/helper-skip.R
@@ -28,3 +28,10 @@ skip_if_no_pyarrow <- function() {
     skip("pyarrow not available for testing")
   }
 }
+
+skip_if_not_dev_mode <- function() {
+  skip_if_not(
+    identical(tolower(Sys.getenv("ARROW_R_DEV")), "true"),
+    "environment variable ARROW_R_DEV"
+  )
+}
diff --git a/r/tests/testthat/test-python.R b/r/tests/testthat/test-python.R
index d78ce2a..6dc91d0 100644
--- a/r/tests/testthat/test-python.R
+++ b/r/tests/testthat/test-python.R
@@ -17,6 +17,16 @@
 
 context("To/from Python")
 
+test_that("install_pyarrow", {
+  skip_on_cran()
+  skip_if_not_dev_mode()
+  skip_if_not_installed("reticulate")
+  venv <- try(reticulate::virtualenv_create("arrow-test"))
+  # Bail out if virtualenv isn't available
+  skip_if(inherits(venv, "try-error"))
+  expect_error(install_pyarrow("arrow-test", nightly = TRUE), NA)
+})
+
 test_that("Array from Python", {
   skip_if_no_pyarrow()
   pa <- reticulate::import("pyarrow")
diff --git a/r/vignettes/python.Rmd b/r/vignettes/python.Rmd
index a1f3881..5ee5654 100644
--- a/r/vignettes/python.Rmd
+++ b/r/vignettes/python.Rmd
@@ -17,19 +17,21 @@ To install it in a virtualenv,
 
 ```r
 library(reticulate)
-virtualenv_create("arrow")
-virtualenv_install("arrow", "pyarrow")
+virtualenv_create("arrow-env")
+install_pyarrow("arrow-env")
 ```
 
 If you want to install a development version of `pyarrow`,
-you can pass `pip_options` to point at Arrow's nightly builds:
+add `nightly = TRUE`:
 
 ```r
-virtualenv_install("arrow", "pyarrow",
-  pip_options = "--extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --force-reinstall")
+install_pyarrow("arrow-env", nightly = TRUE)
 ```
 
-For more on installing and configuring Python, including using `conda`,
+`install_pyarrow()` also works with `conda` environments
+(`conda_create()` instead of `virtualenv_create()`).
+
+For more on installing and configuring Python,
 see the [reticulate docs](https://rstudio.github.io/reticulate/articles/python_packages.html).
 
 ## Using
@@ -39,7 +41,7 @@ To start, load `arrow` and `reticulate`, and then import `pyarrow`.
 ```r
 library(arrow)
 library(reticulate)
-use_virtualenv("arrow")
+use_virtualenv("arrow-env")
 pa <- import("pyarrow")
 ```