diff --git a/.Rbuildignore b/.Rbuildignore index de74a95..08013a6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ ^\.claude$ ^\.playwright-mcp$ ^civilytics-site\.png$ +^Rplots\.pdf$ diff --git a/R/logo.R b/R/logo.R index c3a6d55..c531204 100644 --- a/R/logo.R +++ b/R/logo.R @@ -205,18 +205,18 @@ make_logo_grob <- function(type = c("wordmark", "mark"), #' Add a Civilytics logo to a ggplot (pipe-friendly) #' #' A convenience wrapper that creates the logo grob and attaches it below the -#' plot in one call. Designed for use with the base pipe `|>`: +#' plot in one call. Designed for use with the base pipe `|>`. +#' +#' **Important:** R's `|>` has *higher* precedence than `+`, so you must +#' wrap the ggplot chain in parentheses before piping: #' #' ``` -#' ggplot(mpg, aes(displ, hwy)) + +#' (ggplot(mpg, aes(displ, hwy)) + #' geom_point() + -#' theme_civilytics() |> +#' theme_civilytics()) |> #' civilytics_logo() #' ``` #' -#' Since `|>` has lower precedence than `+`, the entire ggplot chain is piped -#' as the first argument — no parentheses needed. -#' #' @param plot A ggplot object. #' @param type Character. `"wordmark"` (default) or `"mark"`. Passed to #' [make_logo_grob()]. @@ -233,17 +233,17 @@ make_logo_grob <- function(type = c("wordmark", "mark"), #' \dontrun{ #' library(ggplot2); library(grid) #' -#' # Pipe-friendly usage -#' ggplot(mpg, aes(displ, hwy)) + +#' # Pipe usage — parentheses required around the ggplot chain +#' (ggplot(mpg, aes(displ, hwy)) + #' geom_point() + -#' theme_civilytics() |> +#' theme_civilytics()) |> #' civilytics_logo() |> #' grid.draw() #' #' # Dark theme with mark -#' ggplot(mpg, aes(displ, hwy)) + +#' (ggplot(mpg, aes(displ, hwy)) + #' geom_point() + -#' theme_civilytics_dark() |> +#' theme_civilytics_dark()) |> #' civilytics_logo(variant = "dark", type = "mark") |> #' grid.draw() #' } diff --git a/man/civilytics_logo.Rd b/man/civilytics_logo.Rd index 26699a8..5ade49a 100644 --- a/man/civilytics_logo.Rd +++ b/man/civilytics_logo.Rd @@ -29,34 +29,34 @@ A grob (from [gridExtra::arrangeGrob()]) ready to draw with } \description{ A convenience wrapper that creates the logo grob and attaches it below the -plot in one call. Designed for use with the base pipe `|>`: +plot in one call. Designed for use with the base pipe `|>`. } \details{ +**Important:** R's `|>` has *higher* precedence than `+`, so you must +wrap the ggplot chain in parentheses before piping: + ``` -ggplot(mpg, aes(displ, hwy)) + +(ggplot(mpg, aes(displ, hwy)) + geom_point() + - theme_civilytics() |> + theme_civilytics()) |> civilytics_logo() ``` - -Since `|>` has lower precedence than `+`, the entire ggplot chain is piped -as the first argument — no parentheses needed. } \examples{ \dontrun{ library(ggplot2); library(grid) -# Pipe-friendly usage -ggplot(mpg, aes(displ, hwy)) + +# Pipe usage — parentheses required around the ggplot chain +(ggplot(mpg, aes(displ, hwy)) + geom_point() + - theme_civilytics() |> + theme_civilytics()) |> civilytics_logo() |> grid.draw() # Dark theme with mark -ggplot(mpg, aes(displ, hwy)) + +(ggplot(mpg, aes(displ, hwy)) + geom_point() + - theme_civilytics_dark() |> + theme_civilytics_dark()) |> civilytics_logo(variant = "dark", type = "mark") |> grid.draw() } diff --git a/tests/testthat/test_theme.R b/tests/testthat/test_theme.R index 21de497..e7beae7 100644 --- a/tests/testthat/test_theme.R +++ b/tests/testthat/test_theme.R @@ -190,8 +190,11 @@ test_that("civilytics_logo returns a grob", { }) test_that("civilytics_logo works with pipe operator", { - p <- ggplot(mpg, aes(displ, hwy)) + geom_point() + theme_civilytics() - result <- suppressWarnings(p |> civilytics_logo()) + # |> has higher precedence than +, so parens are required + result <- suppressWarnings( + (ggplot(mpg, aes(displ, hwy)) + geom_point() + theme_civilytics()) |> + civilytics_logo() + ) expect_s3_class(result, "grob") })