R/rstudio_section.R

Defines functions rstudio_section

Documented in rstudio_section

#' Converts text to an RStudio section
#'
#' This addon converts text to an RStudio section or code folding block.
#' @export
rstudio_section = function() {

  location = rstudioapi::getActiveDocumentContext()
  ## Get the row number
  r = location$selection[[1]]$range$start[1]
  line = location$contents[r]
  comment_line = paste0(line, " ----")
  is_comment = substr(line, 1L, 2L) == "#'"

  if(!is_comment) {
    comment_line = paste0("# ", comment_line)
  }
  rstudioapi::modifyRange(c(r, 1, r, Inf), comment_line)
}
csgillespie/raddins documentation built on May 14, 2019, 12:23 p.m.