pmap_piece() operates on the rows of a data frame
applying .f to each row (usually grid.piece).
Arguments
- .l
A list of vectors, such as a data frame. The length of
.ldetermines the number of arguments that.fwill be called with. List names will be used if present.- .f
Function to be applied to
.lafter adjustments tocfgandenvirand the application oftrans. Usuallygrid.piece(),pieceGrob(),piece3d(), orpiece().- ...
Extra arguments to pass to
.f.- cfg
Piecepack configuration list or
pp_cfgobject, a list ofpp_cfgobjects, or a character vector referring to names inenviror a character vector referring to object names that can be retrieved bybase::dynGet().- envir
Environment (or named list) containing configuration list(s).
- trans
Function to modify
.lbefore drawing. Default (NULL) is to not modify.l.op_transformcan help with using an oblique projection (i.e.op_scaleover 0).- draw
A logical value indicating whether graphics output should be produced.
- name
A character identifier (for grid)
- gp
An object of class “gpar”.
- vp
A
gridviewport object (orNULL).
Details
pmap_piece() differs from purrr::pmap() in a few ways:
If
cfgand/orenvirare missing attempts to set reasonable defaults.If not
NULLwill first apply functiontransto.l.If the output of
.fis a grid grob object thenpmap_piecewill return agTreeobject with specifiedname,gp, andvpvalues and ifdrawis true draw it.If
.llacks anamecolumn or ifnamecolumn is non-unique attempts to generate a reasonable new defaultnamecolumn and use that to name the returngTreechildren orlistvalues.
See also
render_piece() is a higher-level function that wraps this function.
Examples
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))
grid::grid.newpage()
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")
}