From bcb95cc36bd933d00001b8d4263ff9df7bafb342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 29 May 2023 06:25:15 +0200 Subject: [PATCH] Shortcut for count() --- R/data-mask.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/data-mask.R b/R/data-mask.R index b72a708289..dfce4364c2 100644 --- a/R/data-mask.R +++ b/R/data-mask.R @@ -82,6 +82,13 @@ DataMask <- R6Class("DataMask", }, eval_all_summarise = function(quo) { + # Optimize count() + if (identical(quo_get_expr(quo), expr(n()))) { + if (identical(eval(expr(n), quo_get_env(quo)), expr(n()))) { + return(lengths(private$rows)) + } + } + # Wrap in a function called `eval()` so that rlang ignores the # call in error messages. This only concerns errors that occur # directly in `quo`.