diff --git a/R/expr__expr.R b/R/expr__expr.R index 59e115763..9595e1ca9 100644 --- a/R/expr__expr.R +++ b/R/expr__expr.R @@ -1417,6 +1417,7 @@ Expr_sort = function(..., descending = FALSE, nulls_last = FALSE) { #' @examples #' pl$DataFrame(a = c(6, 1, 0, NA, Inf, NaN))$select(pl$col("a")$top_k(5)) Expr_top_k = function(k, ..., nulls_last = FALSE, maintain_order = FALSE, multithreaded = TRUE) { + check_dots_empty(...) if (!is.numeric(k) || k < 0) stop("k must be numeric and positive, prefereably integerish") .pr$Expr$top_k(self, k, nulls_last = nulls_last, maintain_order = maintain_order, multithreaded = multithreaded) |> unwrap("in $top_k():") diff --git a/R/utils.R b/R/utils.R index 45c246fb3..657c99c00 100644 --- a/R/utils.R +++ b/R/utils.R @@ -678,3 +678,15 @@ is_named = function(x) { } TRUE } + +get_dots <- function(...) { + eval(substitute(alist(...))) +} + +check_dots_empty <- function(...) { + dots <- get_dots(...) + if (length(dots) > 0) { + Err_plain("`...` must be empty. Problematic values:", toString(dots)) |> + unwrap() + } +}