R/fetchSelectedText.R

Defines functions fetchSelectedText

Documented in fetchSelectedText

#' Fetch Selected Text
#'
#' @return The selected text and if it contains alphabets
#'
#' @examples
#' \dontrun{
#' fetchSelectedText()
#' }
#'
#' @export
#'
#'

fetchSelectedText <- function() {
  #fetch the selected text and see if it is valid for the define function
  a <- rstudioapi::getSourceEditorContext()
  s <- a$selection
  selText <- s[[1L]]$text
  alphaLetters <- stringr::str_extract(selText,"[A-z]")
  secArg = FALSE
  if(length(alphaLetters)){
    if(!is.na(alphaLetters)) secArg = TRUE
  }

  return(c(secArg,selText))
}
oobianom/r2dictionary documentation built on July 30, 2023, 12:16 a.m.