pmap_piece: Create graphics using data frame input

View source: R/pmap_piece.R

pmap_pieceR Documentation

Create graphics using data frame input


pmap_piece() operates on the rows of a data frame applying .f to each row (usually grid.piece).


  .f = pieceGrob,
  cfg = getOption("piecepackr.cfg"),
  envir = getOption("piecepackr.envir"),
  trans = getOption("piecepackr.trans"),
  draw = TRUE,
  name = NULL,
  gp = NULL,
  vp = NULL



A list of vectors, such as a data frame. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.


Function to be applied to .l after adjustments to cfg and envir and the application of trans. Usually grid.piece(), pieceGrob(), piece3d(), or piece().


Extra arguments to pass to .f.


Piecepack configuration list or pp_cfg object, a list of pp_cfg objects, or a character vector referring to names in envir or a character vector referring to object names that can be retrieved by base::dynGet().


Environment (or named list) containing configuration list(s).


Function to modify .l before drawing. Default (NULL) is to not modify .l. op_transform can help with using an oblique projection (i.e. op_scale over 0).


A logical value indicating whether graphics output should be produced.


A character identifier (for grid)


An object of class “gpar”.


A grid viewport object (or NULL).


pmap_piece() differs from purrr::pmap() in a few ways:

  1. If cfg and/or envir are missing attempts to set reasonable defaults.

  2. If not NULL will first apply function trans to .l.

  3. If the output of .f is a grid grob object then pmap_piece will return a gTree object with specified name, gp, and vp values and if draw is true draw it.

  4. If .l lacks a name column or if name column is non-unique attempts to generate a reasonable new default name column and use that to name the return gTree children or list values.

See Also

render_piece() is a higher-level function that wraps this function.


  if (requireNamespace("grid", quietly = TRUE) && piecepackr:::device_supports_unicode()) {
       dark_colorscheme <- list(suit_color="darkred,black,darkgreen,darkblue,black",
                            invert_colors.suited=TRUE, border_color="black", border_lex=2)
       traditional_ranks <- list(use_suit_as_ace=TRUE, rank_text=",a,2,3,4,5")
       cfg3d <- list(width.pawn=0.75, height.pawn=0.75, depth.pawn=1,
                          dm_text.pawn="", shape.pawn="convex6", invert_colors.pawn=TRUE,
                          edge_color.coin="tan", edge_color.tile="tan")
       cfg <- pp_cfg(c(dark_colorscheme, traditional_ranks, cfg3d))
       df_tiles <- data.frame(piece_side="tile_back", x=0.5+c(3,1,3,1), y=0.5+c(3,3,1,1),
                              suit=NA, angle=NA, z=NA, stringsAsFactors=FALSE)
       df_coins <- data.frame(piece_side="coin_back", x=rep(4:1, 4), y=rep(4:1, each=4),
                              suit=1:16%%2+rep(c(1,3), each=8),
                              angle=rep(c(180,0), each=8), z=1/4+1/16, stringsAsFactors=FALSE)
       df <- rbind(df_tiles, df_coins)
       pmap_piece(df, cfg=cfg, op_scale=0.5, default.units="in")

trevorld/piecepack documentation built on May 20, 2024, 4:31 a.m.