This is an automated email from the ASF dual-hosted git repository. brycemecum pushed a commit to branch maint-19.0.1-r in repository https://gitbox.apache.org/repos/asf/arrow.git
commit e7206ee22c752426012ce8bbe9079b214edf10b8 Author: Bryce Mecum <[email protected]> AuthorDate: Sun Jan 26 11:37:08 2025 -0800 Add docs for arrow::one --- r/R/dplyr-funcs-agg.R | 31 ++++++++++++++++++++++++------- r/man/one.Rd | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/r/R/dplyr-funcs-agg.R b/r/R/dplyr-funcs-agg.R index 275fca3654..b67af6fc01 100644 --- a/r/R/dplyr-funcs-agg.R +++ b/r/R/dplyr-funcs-agg.R @@ -150,13 +150,7 @@ register_bindings_aggregate <- function() { options = list(skip_nulls = na.rm, min_count = 0L) ) }) - register_binding("arrow::one", function(...) { - set_agg( - fun = "one", - data = ensure_one_arg(list2(...), "one"), - options = list() - ) - }) + register_binding("arrow::one", one) } set_agg <- function(...) { @@ -194,6 +188,29 @@ find_arrow_mask <- function() { n <- n + 1 } } +#' Get one value from each group +#' +#' Returns one arbitrary value from the input for each group. The function is +#' biased towards non-null values: if there is at least one non-null value for a +#' certain group, that value is returned, and only if all the values are null +#' for the group will the function return null. +#' +#' @param ... Unquoted column name to pull values from. +#' +#' @examples +#' \dontrun{ +#' mtcars |> +#' arrow_table() |> +#' group_by(cyl) |> +#' summarize(x = one(disp)) +#' } +one <- function(...) { + set_agg( + fun = "one", + data = ensure_one_arg(list2(...), "one"), + options = list() + ) +} ensure_one_arg <- function(args, fun) { if (length(args) == 0) { diff --git a/r/man/one.Rd b/r/man/one.Rd new file mode 100644 index 0000000000..5b672b5c19 --- /dev/null +++ b/r/man/one.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dplyr-funcs-agg.R +\name{one} +\alias{one} +\title{Get one value from each group} +\usage{ +one(...) +} +\arguments{ +\item{...}{Unquoted column name to pull values from.} +} +\description{ +Returns one arbitrary value from the input for each group. The +function is biased towards non-null values: if there is at least one non-null +value for a certain group, that value is returned, and only if all the values +are null for the group will the function return null. +} +\examples{ +\dontrun{ +mtcars |> + arrow_table() |> + group_by(cyl) |> + summarize(x = one(disp)) +} +}
