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))
}

Try the r2dictionary package in your browser

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

r2dictionary documentation built on July 26, 2023, 5:34 p.m.