R/get_grobFromGtable.R

Defines functions get_grobFromGtable.l_facet_grid get_grobFromGtable.l_facet_wrap get_grobFromGtable.l_facet_ggplot get_grobFromGtable

get_grobFromGtable <- function(l_className, gtable, widgets) {
  class(l_className) <- l_className
  UseMethod("get_grobFromGtable", l_className)
}

get_grobFromGtable.l_facet_ggplot <- function(l_className, gtable, widgets) {
  
  grobs <- if(is.gtable(gtable)) gtable$grobs else 
    stop("It is not a `gtable` object", call. = FALSE)
  
  wNames <- sapply(widgets, as.character)
  
  gs <- lapply(grobs, 
               function(grob) {
                 if(is.gtable(grob)) {
                   g <- grob$grobs
                   g[names(g) %in% wNames]
                 } else NULL
               })
  
  unlist(gs, recursive = FALSE)
}

get_grobFromGtable.l_facet_wrap <- function(l_className, gtable, widgets) {
  
  grobs <- if(is.gtable(gtable)) gtable$grobs else 
    stop("It is not a `gtable` object", call. = FALSE)
  
  wNames <- sapply(widgets, as.character)
  
  gs <- lapply(grobs, 
               function(grob) {
                 if(is.gtable(grob)) {
                   g <- grob$grobs
                   g[names(g) %in% wNames]
                 } else NULL
               })
  
  unlist(gs, recursive = FALSE)
}

get_grobFromGtable.l_facet_grid <- function(l_className, gtable, widgets) {
  
  grobs <- if(is.gtable(gtable)) gtable$grobs else 
    stop("It is not a `gtable` object", call. = FALSE)
  
  wNames <- sapply(widgets, as.character)
  gs <- lapply(grobs, 
               function(grob) {
                 if(is.gtable(grob)) {
                   g <- grob$grobs
                   namesG <- vapply(g, function(x) x$name, character(1L))
                   g[namesG %in% wNames]
                 } else NULL
               })
  
  unlist(gs, recursive = FALSE)
}

is.gtable <- function (x) {
  inherits(x, "gtable")
}

Try the loon.shiny package in your browser

Any scripts or data that you put into this service are public.

loon.shiny documentation built on Oct. 8, 2022, 5:05 p.m.