From 44a1a2420ded6f717dcce9d200462933fbbf7c91 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Mon, 24 Jun 2024 21:00:08 +0000 Subject: [PATCH 1/2] Prune ggplot2 --- DESCRIPTION | 1 - NAMESPACE | 6 ------ R/tiltIndicator-package.R | 6 ------ 3 files changed, 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ce34d626..d7dd6761 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,6 @@ Depends: R (>= 4.1.0) Imports: dplyr, - ggplot2, glue, lifecycle, magrittr, diff --git a/NAMESPACE b/NAMESPACE index 0972bfed..1d8ff674 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -95,12 +95,6 @@ importFrom(dplyr,summarise) importFrom(dplyr,summarize) importFrom(dplyr,ungroup) importFrom(dplyr,where) -importFrom(ggplot2,aes) -importFrom(ggplot2,facet_grid) -importFrom(ggplot2,geom_col) -importFrom(ggplot2,ggplot) -importFrom(ggplot2,scale_fill_gradient2) -importFrom(ggplot2,scale_x_discrete) importFrom(glue,glue) importFrom(lifecycle,deprecate_warn) importFrom(lifecycle,deprecated) diff --git a/R/tiltIndicator-package.R b/R/tiltIndicator-package.R index 3b2050c9..a2c910b4 100644 --- a/R/tiltIndicator-package.R +++ b/R/tiltIndicator-package.R @@ -35,12 +35,6 @@ #' @importFrom dplyr summarize #' @importFrom dplyr ungroup #' @importFrom dplyr where -#' @importFrom ggplot2 aes -#' @importFrom ggplot2 facet_grid -#' @importFrom ggplot2 geom_col -#' @importFrom ggplot2 ggplot -#' @importFrom ggplot2 scale_fill_gradient2 -#' @importFrom ggplot2 scale_x_discrete #' @importFrom glue glue #' @importFrom lifecycle deprecate_warn #' @importFrom lifecycle deprecated From e142542eb1f041378101982d9923c2bbe451404c Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Mon, 24 Jun 2024 21:06:19 +0000 Subject: [PATCH 2/2] Prune tidy-evel --- NAMESPACE | 9 ---- R/tiltIndicator-package.R | 2 + R/utils-tidy-eval.R | 107 -------------------------------------- man/tidyeval.Rd | 98 ---------------------------------- 4 files changed, 2 insertions(+), 214 deletions(-) delete mode 100644 R/utils-tidy-eval.R delete mode 100644 man/tidyeval.Rd diff --git a/NAMESPACE b/NAMESPACE index 1d8ff674..612ca55c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,19 +8,13 @@ S3method(rowid,default) S3method(summarize_range,data.frame) S3method(summarize_range,list) export("%>%") -export(":=") -export(.data) export(aka) -export(as_label) -export(as_name) export(categorize_risk) export(document_default_value) export(document_tilt_profile) export(emissions_profile) export(emissions_profile_any_compute_profile_ranking) export(emissions_profile_upstream) -export(enquo) -export(enquos) export(epa_at_company_level) export(epa_compute_profile_ranking) export(example_companies) @@ -109,14 +103,11 @@ importFrom(purrr,walk) importFrom(readr,col_character) importFrom(readr,cols) importFrom(readr,read_csv) -importFrom(rlang,":=") importFrom(rlang,.data) importFrom(rlang,.env) importFrom(rlang,abort) -importFrom(rlang,as_label) importFrom(rlang,as_name) importFrom(rlang,enquo) -importFrom(rlang,enquos) importFrom(rlang,is_empty) importFrom(rlang,is_named) importFrom(rlang,quo_get_expr) diff --git a/R/tiltIndicator-package.R b/R/tiltIndicator-package.R index a2c910b4..b55616da 100644 --- a/R/tiltIndicator-package.R +++ b/R/tiltIndicator-package.R @@ -48,9 +48,11 @@ #' @importFrom readr col_character #' @importFrom readr cols #' @importFrom readr read_csv +#' @importFrom rlang .data #' @importFrom rlang .env #' @importFrom rlang abort #' @importFrom rlang as_name +#' @importFrom rlang enquo #' @importFrom rlang is_empty #' @importFrom rlang is_named #' @importFrom rlang quo_get_expr diff --git a/R/utils-tidy-eval.R b/R/utils-tidy-eval.R deleted file mode 100644 index 09c3698c..00000000 --- a/R/utils-tidy-eval.R +++ /dev/null @@ -1,107 +0,0 @@ -#' Tidy eval helpers -#' -#' @description -#' This page lists the tidy eval tools reexported in this package from -#' rlang. To learn about using tidy eval in scripts and packages at a -#' high level, see the [dplyr programming -#' vignette](https://dplyr.tidyverse.org/articles/programming.html) -#' and the [ggplot2 in packages -#' vignette](https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html). -#' The [Metaprogramming -#' section](https://adv-r.hadley.nz/metaprogramming.html) of [Advanced -#' R](https://adv-r.hadley.nz) may also be useful for a deeper dive. -#' -#' * The tidy eval operators `{{`, `!!`, and `!!!` are syntactic -#' constructs which are specially interpreted by tidy eval functions. -#' You will mostly need `{{`, as `!!` and `!!!` are more advanced -#' operators which you should not have to use in simple cases. -#' -#' The curly-curly operator `{{` allows you to tunnel data-variables -#' passed from function arguments inside other tidy eval functions. -#' `{{` is designed for individual arguments. To pass multiple -#' arguments contained in dots, use `...` in the normal way. -#' -#' ``` -#' my_function <- function(data, var, ...) { -#' data %>% -#' group_by(...) %>% -#' summarise(mean = mean({{ var }})) -#' } -#' ``` -#' -#' * [enquo()] and [enquos()] delay the execution of one or several -#' function arguments. The former returns a single expression, the -#' latter returns a list of expressions. Once defused, expressions -#' will no longer evaluate on their own. They must be injected back -#' into an evaluation context with `!!` (for a single expression) and -#' `!!!` (for a list of expressions). -#' -#' ``` -#' my_function <- function(data, var, ...) { -#' # Defuse -#' var <- enquo(var) -#' dots <- enquos(...) -#' -#' # Inject -#' data %>% -#' group_by(!!!dots) %>% -#' summarise(mean = mean(!!var)) -#' } -#' ``` -#' -#' In this simple case, the code is equivalent to the usage of `{{` -#' and `...` above. Defusing with `enquo()` or `enquos()` is only -#' needed in more complex cases, for instance if you need to inspect -#' or modify the expressions in some way. -#' -#' * The `.data` pronoun is an object that represents the current -#' slice of data. If you have a variable name in a string, use the -#' `.data` pronoun to subset that variable with `[[`. -#' -#' ``` -#' my_var <- "disp" -#' mtcars %>% summarise(mean = mean(.data[[my_var]])) -#' ``` -#' -#' * Another tidy eval operator is `:=`. It makes it possible to use -#' glue and curly-curly syntax on the LHS of `=`. For technical -#' reasons, the R language doesn't support complex expressions on -#' the left of `=`, so we use `:=` as a workaround. -#' -#' ``` -#' my_function <- function(data, var, suffix = "foo") { -#' # Use `{{` to tunnel function arguments and the usual glue -#' # operator `{` to interpolate plain strings. -#' data %>% -#' summarise("{{ var }}_mean_{suffix}" := mean({{ var }})) -#' } -#' ``` -#' -#' * Many tidy eval functions like `dplyr::mutate()` or -#' `dplyr::summarise()` give an automatic name to unnamed inputs. If -#' you need to create the same sort of automatic names by yourself, -#' use `as_label()`. For instance, the glue-tunnelling syntax above -#' can be reproduced manually with: -#' -#' ``` -#' my_function <- function(data, var, suffix = "foo") { -#' var <- enquo(var) -#' prefix <- as_label(var) -#' data %>% -#' summarise("{prefix}_mean_{suffix}" := mean(!!var)) -#' } -#' ``` -#' -#' Expressions defused with `enquo()` (or tunnelled with `{{`) need -#' not be simple column names, they can be arbitrarily complex. -#' `as_label()` handles those cases gracefully. If your code assumes -#' a simple column name, use `as_name()` instead. This is safer -#' because it throws an error if the input is not a name as expected. -#' -#' @md -#' @name tidyeval -#' @keywords internal -#' @importFrom rlang enquo enquos .data := as_name as_label -#' @aliases enquo enquos .data := as_name as_label -#' @export enquo enquos .data := as_name as_label -NULL diff --git a/man/tidyeval.Rd b/man/tidyeval.Rd deleted file mode 100644 index f773abf2..00000000 --- a/man/tidyeval.Rd +++ /dev/null @@ -1,98 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-tidy-eval.R -\name{tidyeval} -\alias{tidyeval} -\alias{enquo} -\alias{enquos} -\alias{.data} -\alias{:=} -\alias{as_name} -\alias{as_label} -\title{Tidy eval helpers} -\description{ -This page lists the tidy eval tools reexported in this package from -rlang. To learn about using tidy eval in scripts and packages at a -high level, see the \href{https://dplyr.tidyverse.org/articles/programming.html}{dplyr programming vignette} -and the \href{https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html}{ggplot2 in packages vignette}. -The \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming section} of \href{https://adv-r.hadley.nz}{Advanced R} may also be useful for a deeper dive. -\itemize{ -\item The tidy eval operators \verb{\{\{}, \verb{!!}, and \verb{!!!} are syntactic -constructs which are specially interpreted by tidy eval functions. -You will mostly need \verb{\{\{}, as \verb{!!} and \verb{!!!} are more advanced -operators which you should not have to use in simple cases. - -The curly-curly operator \verb{\{\{} allows you to tunnel data-variables -passed from function arguments inside other tidy eval functions. -\verb{\{\{} is designed for individual arguments. To pass multiple -arguments contained in dots, use \code{...} in the normal way. - -\if{html}{\out{
}}\preformatted{my_function <- function(data, var, ...) \{ - data \%>\% - group_by(...) \%>\% - summarise(mean = mean(\{\{ var \}\})) -\} -}\if{html}{\out{
}} -\item \code{\link[=enquo]{enquo()}} and \code{\link[=enquos]{enquos()}} delay the execution of one or several -function arguments. The former returns a single expression, the -latter returns a list of expressions. Once defused, expressions -will no longer evaluate on their own. They must be injected back -into an evaluation context with \verb{!!} (for a single expression) and -\verb{!!!} (for a list of expressions). - -\if{html}{\out{
}}\preformatted{my_function <- function(data, var, ...) \{ - # Defuse - var <- enquo(var) - dots <- enquos(...) - - # Inject - data \%>\% - group_by(!!!dots) \%>\% - summarise(mean = mean(!!var)) -\} -}\if{html}{\out{
}} - -In this simple case, the code is equivalent to the usage of \verb{\{\{} -and \code{...} above. Defusing with \code{enquo()} or \code{enquos()} is only -needed in more complex cases, for instance if you need to inspect -or modify the expressions in some way. -\item The \code{.data} pronoun is an object that represents the current -slice of data. If you have a variable name in a string, use the -\code{.data} pronoun to subset that variable with \code{[[}. - -\if{html}{\out{
}}\preformatted{my_var <- "disp" -mtcars \%>\% summarise(mean = mean(.data[[my_var]])) -}\if{html}{\out{
}} -\item Another tidy eval operator is \verb{:=}. It makes it possible to use -glue and curly-curly syntax on the LHS of \code{=}. For technical -reasons, the R language doesn't support complex expressions on -the left of \code{=}, so we use \verb{:=} as a workaround. - -\if{html}{\out{
}}\preformatted{my_function <- function(data, var, suffix = "foo") \{ - # Use `\{\{` to tunnel function arguments and the usual glue - # operator `\{` to interpolate plain strings. - data \%>\% - summarise("\{\{ var \}\}_mean_\{suffix\}" := mean(\{\{ var \}\})) -\} -}\if{html}{\out{
}} -\item Many tidy eval functions like \code{dplyr::mutate()} or -\code{dplyr::summarise()} give an automatic name to unnamed inputs. If -you need to create the same sort of automatic names by yourself, -use \code{as_label()}. For instance, the glue-tunnelling syntax above -can be reproduced manually with: - -\if{html}{\out{
}}\preformatted{my_function <- function(data, var, suffix = "foo") \{ - var <- enquo(var) - prefix <- as_label(var) - data \%>\% - summarise("\{prefix\}_mean_\{suffix\}" := mean(!!var)) -\} -}\if{html}{\out{
}} - -Expressions defused with \code{enquo()} (or tunnelled with \verb{\{\{}) need -not be simple column names, they can be arbitrarily complex. -\code{as_label()} handles those cases gracefully. If your code assumes -a simple column name, use \code{as_name()} instead. This is safer -because it throws an error if the input is not a name as expected. -} -} -\keyword{internal}