R/coord_utils.R

Defines functions replace_coords split_coord

Documented in split_coord

#' Split a TikZ coordinate.
#'
#' @param coord Coordinate string of the form "(x,y)"
#'
#' @returns A character vector of length 2: The x and y components of the
#'  coordinate. These may contain spaces.
split_coord <- function(coord) {
    pattern_components <- "\\(([^,]*),([^\\)]*)\\)"
    components <- stringr::str_match(coord, pattern_components)
    x <- components[1,2]
    y <- components[1,3]

    return(c(x, y))
}


replace_coords <- function(tikz_code, replace_func) {
    pattern_coord <- "\\([^\\)]*,.*?\\)"
    result <- stringr::str_replace_all(tikz_code, pattern_coord, replace_func)

    return(result)
}

Try the ggtikz package in your browser

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

ggtikz documentation built on June 22, 2024, 10:01 a.m.