Repository navigation
Commit 48ee38f
committed
ARROW-5488: [R] Workaround when C++ lib not available
This is very much a work in progress. The idea is to replace the code generation that is usually done by `Rcpp::compileAttributes()` with something custom. This is driven by the `data-raw/codegen.R` file, which I'll polish. I'm opening this right now for feedback opportunities.
All of the `.cpp` files are guarded by :
```
#if defined(ARROW_R_WITH_ARROW)
...
#endif
```
And `ARROW_R_WITH_ARROW` is defined via the configure file, if the library was indeed used.
For example, this function:
```cpp
// [[arrow::export]]
std::shared_ptr<arrow::Column> ipc___feather___TableReader__GetColumn(
const std::unique_ptr<arrow::ipc::feather::TableReader>& reader, int i) {
std::shared_ptr<arrow::Column> column;
STOP_IF_NOT_OK(reader->GetColumn(i, &column));
return column;
}
```
triggers generation of this in the `generated.cpp` file:
```cpp
#if defined(ARROW_R_WITH_ARROW)
std::string ipc___feather___TableReader__GetColumnName(const std::unique_ptr<arrow::ipc::feather::TableReader>& reader, int i);
SEXP _arrow_ipc___feather___TableReader__GetColumnName(SEXP reader_sexp, SEXP i_sexp){
BEGIN_RCPP
Rcpp::traits::input_parameter<const std::unique_ptr<arrow::ipc::feather::TableReader>&>::type reader(reader_sexp);
Rcpp::traits::input_parameter<int>::type i(i_sexp);Rcpp::Shield<SEXP> rcpp_result_gen(Rcpp::wrap(ipc___feather___TableReader__GetColumnName( reader, i)));
return rcpp_result_gen;
END_RCPP
}
#else
SEXP _arrow_ipc___feather___TableReader__GetColumnName(SEXP reader_sexp, SEXP i_sexp){
BEGIN_RCPP
Rcpp::stop("arrow C++ library not available");
END_RCPP
}
#endif
```
So the generated R api `SEXP`y functions only call the real thing when the c++ library is available, otherwise they just throw an error.
and this in the `generated.R` file:
```r
ipc___feather___TableReader__GetColumnName <- function(reader, i) {
.Call(`_arrow_ipc___feather___TableReader__GetColumnName` , reader, i )
}
```
This also needed some extra care in test functions so that the tests only run if Arrow is available.
@wesm comment from https://issues.apache.org/jira/browse/ARROW-5488 might be more practical and closer to what @jjallaire mentioned about how the `RcppParallel` package does it with Intel tbb:
https://github.com/RcppCore/RcppParallel/blob/master/R/hooks.R
> One possibility is to bundle the Arrow header files with the CRAN package and build against them, but do not include libarrow and libparquet when linking. When the library is loaded, the libraries must be loaded in-process via dlopen before loading the Rcpp extensions. The C++ libraries can be installed then after the fact
Author: Romain Francois <romain@rstudio.com>
Author: Romain François <romain@rstudio.com>
Closes apache#4471 from romainfrancois/ARROW-5488/workaround and squashes the following commits:
d13dbfb <Romain Francois> update error message to mention arrow::install_arrow()
1b6a737 <Romain Francois> Merge branch 'ARROW-5488/workaround' of https://github.com/romainfrancois/arrow into ARROW-5488/workaround
418fc2d <Romain Francois> mention codegen in the README
9a1b3e6 <Romain Francois> glue() not needed here
496eaf5 <Romain Francois> when brew is available but apache-arrow is not installed, install it
b8a6576 <Romain Francois> no need for stringr
238fa14 <Romain Francois> rm message about ARROW_R_DEV not being set
9788811 <Romain François> Merge branch 'master' into ARROW-5488/workaround
346978d <Romain Francois> update docker files.
bb9eed2 <Romain Francois> not showing diff for generated files
1df1e39 <Romain Francois> phrase shim message more positively
3b04369 <Romain Francois> use `\dontrun{}` in examples
562670d <Romain Francois> RcppExport all the things
6c06581 <Romain Francois> Using arrow:::arrow_available()
75b0751 <Romain Francois> Move symbols.h back into arrow_types.h
bd7f30d <Romain Francois> 🐀
e8ac3ea <Romain Francois> using arrowExports.(R,cpp). update configure script
84fa149 <Romain Francois> lint
54ee38d <Romain Francois> 🐀
d9e4f94 <Romain Francois> added a second R job to install and check the package on a system without libarrow
0479a75 <Romain Francois> code generation without rap package, using purrr instead
008eaf4 <Romain Francois> update generated code, fix merge conflicts
f957504 <Romain Francois> update test_that shim
1170236 <Romain Francois> not necessary
1ed5596 <Romain Francois> Workaround so that the R package still checks without the C++ library.
78f69af <Romain Francois> move symbols declaration to their own file, might end up be generated automatically later somehow.1 parent 9c753c4 commit 48ee38f
49 files changed
Lines changed: 4997 additions & 3746 deletions
File tree
- ci
- cpp/build-support
- dev/release
- r
- R
- data-raw
- man
- src
- tests
- testthat
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
369 | 384 | | |
370 | 385 | | |
371 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | | - | |
| 196 | + | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 51 | + | |
| 52 | + | |
57 | 53 | | |
58 | | - | |
| 54 | + | |
59 | 55 | | |
60 | 56 | | |
61 | 57 | | |
| |||
67 | 63 | | |
68 | 64 | | |
69 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | 99 | | |
101 | 100 | | |
102 | 101 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
108 | | - | |
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
112 | 110 | | |
| 111 | + | |
113 | 112 | | |
114 | 113 | | |
115 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
74 | | - | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
0 commit comments