Skip to content

Commit 08096d4

Browse files
paleolimbotthisisnic
authored andcommitted
ARROW-15193: [R][Documentation] Update R binding documentation
Now that #11904 is merged (ARROW-15010), we have slightly different syntax for defining bindings between compute C++ and R functions. @thisisnic wrote some excellent documentation for creating bindings which needs a few tweaks to reflect how this is now done! Closes #12075 from paleolimbot/r-binding-docs Authored-by: Dewey Dunnington <dewey@fishandwhistle.net> Signed-off-by: Nic Crane <thisisnic@gmail.com>
1 parent b596f29 commit 08096d4

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

r/vignettes/developers/bindings.Rmd

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,22 @@ adding to the `nse_funcs` list in `arrow/r/R/dplyr-functions.R`. Here is how
194194
this might look for `startsWith()`:
195195
196196
```{r, eval = FALSE}
197-
nse_funcs$startsWith <- function(x, prefix) {
197+
register_binding("startsWith", function(x, prefix) {
198198
Expression$create(
199199
"starts_with",
200200
x,
201201
options = list(pattern = prefix)
202202
)
203-
}
203+
})
204204
```
205205

206+
In the source files, all the `register_binding()` calls are wrapped in functions
207+
that are called on package load. These are separated into files based on
208+
subject matter (e.g., `R/dplyr-funcs-math.R`, `R/dplyr-funcs-string.R`): find the
209+
closest analog to the function whose binding is being defined and define the
210+
new binding in a similar location. For example, the binding for `startsWith()`
211+
is registered in `dplyr-funcs-string.R` next to the binding for `endsWith()`.
212+
206213
Hint: you can use `call_function()` to call a compute function directly from R.
207214
This might be useful if you want to experiment with a compute function while
208215
you're writing bindings for it, e.g.
@@ -217,9 +224,15 @@ call_function(
217224

218225
## Step 4 - Run (and potentially add to) your tests.
219226

220-
In the process of implementing the function, you may end up implementing more
221-
tests, for example if you discover unusual edge cases. This is fine - add them
222-
to the ones you wrote originally, and run them all. If they pass, you're done!
223-
Submit a PR. If you've modified the C++ code in the
227+
In the process of implementing the function, you will need at least one test
228+
to make sure that your binding works and that future changes to the Arrow R
229+
package don't break it! Bindings are tested in files that correspond to
230+
the file in which they were defined (e.g., `startsWith()` is tested in
231+
`tests/testthat/test-dplyr-funcs-string.R`) next to the tests for `endsWith()`.
232+
233+
You may end up implementing more tests, for example if you discover unusual
234+
edge cases. This is fine - add them to the ones you wrote originally,
235+
and run them all. If they pass, you're done and you can submit a PR.
236+
If you've modified the C++ code in the
224237
R package (for example, when hooking up a binding to its options class), you
225238
should make sure to run `arrow/r/lint.sh` to lint the code.

0 commit comments

Comments
 (0)