R/fold.R

Defines functions summary_fold foldend foldstart

Documented in foldend foldstart

#' @title Roxygen2 Documentation Folding
#' @description Insert more information to function documentation 
#'  without overwhelming the user by using foldstart and foldend macros.
#' @param title Title of the folded section, Default: NULL
#' @return character
#' @details
#'  To enable this feature add to the  `DESCRIPTION` file 
#'  before rendering the `roxygen2`:
#'  
#'  \strong{Roxygen: list(markdown = TRUE)}
#'  
#' @examples 
#' 
#' # With title
#' 
#'  "#' \foldstart{This is an example}
#'  
#'   #' DOCUMENTATION
#'  
#'   #' \foldend"
#' 
#' 
#' # With no title
#' 
#'  "#' \foldstart{}
#'  
#'   #' DOCUMENTATION
#'  
#'   #' \foldend"
#'  
#' @rdname fold
#' @family fold
#' @export 

foldstart <- function(title = NULL){
  
  if(is.null(title)){
    
    ret <- "\\if{html}{\\out{<br><details>}}"
    
  }else{
    
    ret <- sprintf("\\if{html}{\\out{<br><details>%s}}",
                   summary_fold(title))
    
}

  ret
    
}

#' @rdname fold
#' @export 
foldend <- function(){
  '\\if{html}{\\out{</details>}}'
}

summary_fold <- function(txt= ''){
  sprintf("<summary> <span title='Click to Expand'> %s </span> </summary>",txt)
}

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.