R/geometric.R

Defines functions square print.square diamond print.diamond

Documented in diamond square

#' geometric emoji
#'
#' @rdname geometric
#' @param size size
#' @param color color
#'
#' @details
#' For `square`:
#' - `size` should be one of `c( "small", "medium", "medium-small", "large" )`
#' - `color` should be "white" or "black"
#'
#' For `diamond`
#' - `size` should be "large" or "small"
#' - `color` should be "orange" or "blue"
#'
#' @examples
#' \dontrun{
#' square( "small", "black" )
#' square( "large", "white" )
#'
#' diamond( "small", "orange")
#' }
#'
#' @importFrom glue glue
#'
#' @export
square <- function(size = c( "small", "medium", "medium-small", "large" ), color = c( "white", "black") ){
  size <- match.arg(size)
  color <- match.arg(color)

  jis <- emo::jis
  emoji <- jis$emoji[ jis$name == glue("{color} {size} square") ]

  structure(
    emoji,
    class = c("square", "geometric", "emoji"),
    size = size,
    color = color
  )

}

#' @export
print.square <- function(x, ...) {
  NextMethod()
}

#' @rdname geometric
#' @export
diamond <- function( size = c("large", "small"), color = c("orange", "blue") ){
  size <- match.arg(size)
  color <- match.arg(color)

  jis <- emo::jis
  emoji <- jis$emoji[ jis$name == glue("{size} {color} diamond") ]

  structure(
    data$emoji,
    class = c("diamond", "geometric", "emoji"),
    size = size,
    color = color
  )

}

#' @export
print.diamond <- function(x, ...) {
  NextMethod()
}
hadley/emo documentation built on Dec. 16, 2019, 3:42 p.m.