R/read.R

Defines functions read_text capture.print

#' @importFrom utils capture.output
capture.print <- function(obj,comment = NA,...){
  
  if(details_env$device){
    
    if(details_env$imgur)
      obj <- sprintf('![](%s)',imgur_upload(obj))
    
  }else{

    if(!inherits(obj,'character')){
      
      obj <- utils::capture.output(print(obj,...))  
      
    }
        
  }
  
  if(!is.na(comment))
    obj <- paste0(comment,' ',obj)
  
  paste0(obj,collapse = '\n')
}

read_text <- function(text){

  if(!inherits(text,'character')||length(text)>1)
    return(text)
  
  if(!details_env$device){
    if(file.exists(text)){
      text <- readLines(text,warn = FALSE)
    }
  }
  
  text
}

Try the details package in your browser

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

details documentation built on March 28, 2022, 1:06 a.m.