Skip to content

{ggplot2} theme_set() with {targets} and crew_controller_local() #144

Closed Answered by wlandau
gregrs-uk asked this question in Q&A
Discussion options

You must be logged in to vote

I think this is because ggplot2::theme_set() sets the theme in a local package environment inside ggplot2 instead the environment that targets ships to the workers (tar_option_get("envir"), which is usually .GlobalEnv).

> ggplot2::theme_set
function (new) 
{
    old <- ggplot_global$theme_current
    ggplot_global$theme_current <- new
    invisible(old)
}

On each worker, ggplot2 is loaded from scratch and does not know the modifications to the ggplot_global object hidden inside the ggplot2 package environment. As an alternative, you could encapsulate theme_set() inside a global function and then call it in each ggplot target.

library(targets)
library(crew)
library(ggplot2)

tar_option_set…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gregrs-uk
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants