Skip to content

Commit 22acbc9

Browse files
authored
GH-46632: [R][Docs] Add docs for arrow::one (#46648)
### Rationale for this change Adds missing documentation for the `arrow::one` binding. ### What changes are included in this PR? I pulled out the inline definition into a standalone one so we can document it with Roxygen and added Roxygen docs. I cherry-picked d03d3e7 to do this. ### Are these changes tested? Yes. I cherry-picked d03d3e7 which I've tested previously. ### Are there any user-facing changes? No. * GitHub Issue: #46632 Authored-by: Bryce Mecum <[email protected]> Signed-off-by: Bryce Mecum <[email protected]>
1 parent 53b4af4 commit 22acbc9

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

r/R/dplyr-funcs-agg.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,7 @@ register_bindings_aggregate <- function() {
150150
options = list(skip_nulls = na.rm, min_count = 0L)
151151
)
152152
})
153-
register_binding("arrow::one", function(...) {
154-
set_agg(
155-
fun = "one",
156-
data = ensure_one_arg(list2(...), "one"),
157-
options = list()
158-
)
159-
})
153+
register_binding("arrow::one", one)
160154
}
161155

162156
set_agg <- function(...) {
@@ -194,6 +188,29 @@ find_arrow_mask <- function() {
194188
n <- n + 1
195189
}
196190
}
191+
#' Get one value from each group
192+
#'
193+
#' Returns one arbitrary value from the input for each group. The function is
194+
#' biased towards non-null values: if there is at least one non-null value for a
195+
#' certain group, that value is returned, and only if all the values are null
196+
#' for the group will the function return null.
197+
#'
198+
#' @param ... Unquoted column name to pull values from.
199+
#'
200+
#' @examples
201+
#' \dontrun{
202+
#' mtcars |>
203+
#' arrow_table() |>
204+
#' group_by(cyl) |>
205+
#' summarize(x = one(disp))
206+
#' }
207+
one <- function(...) {
208+
set_agg(
209+
fun = "one",
210+
data = ensure_one_arg(list2(...), "one"),
211+
options = list()
212+
)
213+
}
197214

198215
ensure_one_arg <- function(args, fun) {
199216
if (length(args) == 0) {

r/man/one.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)