mercredi 25 août 2021

How do I build my R package such that I can quickly adjust some style changes (e.g. main colors/font size)

I am working on my own R package. I am at the point where I want to write some functions that will visualise my data. I want to be able to quickly adjust the style of all my functions when I'm not happy with some configurations. Examples of this will be:

  • Font size
  • Primary/secondary colors
  • Green/Orange/Red colors

Because, suppose I have graphs.R:

graph_a <- function(font_size = 9, primary_color = "#ffffff") { ... }

graph_b <- function(font_size = 9, primary_color = "#ffffff") { ... }

graph_c <- function(font_size = 9, primary_color = "#ffffff") { ... }

It would be a hassle to change all the pre-defined values if I want to increase my font size a bit. I was thinking of using a global constant, but cannot find anything on this on Google, and using a config file seems not the proper tactic as well. The first thing that comes to mind is add the following at the first line of graphs.R:

FONT_SIZE <- 9
PRIMARY_COLOR <- "#ffffff"

But what if I want to use these across my package?

Aucun commentaire:

Enregistrer un commentaire