R/rd-name-alias.R

Defines functions topic_add_name_aliases format.rd_section_name roxy_tag_parse.roxy_tag_name format.rd_section_alias roxy_tag_parse.roxy_tag_aliases

#' @export
roxy_tag_parse.roxy_tag_aliases <- function(x) tag_value(x)
#' @export
format.rd_section_alias <- function(x, ...) {
  x$value <- str_replace_all(x$value, fixed("%"), "\\%")
  format_rd(x, ..., sort = FALSE)
}

#' @export
roxy_tag_parse.roxy_tag_name <- function(x) tag_value(x)
#' @export
format.rd_section_name <- function(x, ...) {
  x$value <- str_replace_all(x$value, fixed("%"), "\\%")
  format_first(x, ...)
}

topic_add_name_aliases <- function(topic, block, name) {
  tags <- block_get_tags(block, "aliases")

  if (length(tags) == 0) {
    aliases <- character()
  } else {
    vals <- map_chr(tags, "val")
    aliases <- unlist(str_split(vals, "\\s+"))
  }

  if (any(aliases == "NULL")) {
    # Don't add default aliases
    aliases <- setdiff(aliases, "NULL")
  } else {
    aliases <- c(name, block$object$alias, aliases)
  }
  aliases <- unique(aliases)

  topic$add(rd_section("name", name))
  topic$add(rd_section("alias", aliases))
}

Try the roxygen2 package in your browser

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

roxygen2 documentation built on Sept. 8, 2021, 9:08 a.m.