From 1204e13e662d7f44ab2909a3e735b078232e65e4 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Fri, 26 Apr 2019 21:48:51 +0200 Subject: [PATCH] Move build-time calculations to .onLoad() --- R/grob-null.r | 4 +++- R/theme-current.R | 2 +- R/zzz.r | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/R/grob-null.r b/R/grob-null.r index 5af4c40ca5..06dcb75a6d 100644 --- a/R/grob-null.r +++ b/R/grob-null.r @@ -4,7 +4,9 @@ #' @export zeroGrob <- function() .zeroGrob -.zeroGrob <- grob(cl = "zeroGrob", name = "NULL") +# Will get assigned in .onLoad() +.zeroGrob <- NULL + #' @export #' @method widthDetails zeroGrob widthDetails.zeroGrob <- function(x) unit(0, "cm") diff --git a/R/theme-current.R b/R/theme-current.R index 7bb0f061b1..ac860f9371 100644 --- a/R/theme-current.R +++ b/R/theme-current.R @@ -1,6 +1,6 @@ #' @include theme-defaults.r #' @include theme-elements.r -ggplot_global$theme_current <- theme_gray() +NULL #' Get, set, and modify the active theme #' diff --git a/R/zzz.r b/R/zzz.r index 9e569b2087..3e5843be7b 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -19,6 +19,10 @@ .onLoad <- function(...) { backport_unit_methods() + .zeroGrob <<- grob(cl = "zeroGrob", name = "NULL") + + ggplot_global$theme_current <- theme_gray() + # To avoid namespace clash with dplyr. # It seems surprising that this hack works if (requireNamespace("dplyr", quietly = TRUE)) {