R/write_tableHTML.R

Defines functions write_tableHTML

Documented in write_tableHTML

#' Writes the HTML code to a file 
#'
#' \code{write_tableHTML} will write the HTML code to a file
#' 
#' \code{write_tableHTML} will write the HTML code to a file.
#'
#' @param tableHTML A tableHTML object created by the tableHTML function.
#'
#' @param file A character string. This is the file name. You need to include the extention.
#' 
#' @param complete_html Either TRUE or FALSE. Defaults to FALSE. If TRUE then the <html> and <body>
#'   tags are also added in the file.
#'
#' @return The function itself returns nothing but a file is created. 
#'         
#' @examples
#' \dontrun{
#' write_tableHTML(tableHTML(mtcars), file = 'myhtmlcode.html')
#' 
#' write_tableHTML(tableHTML(mtcars), file = 'myhtmlcode.html', complete_html = TRUE)
#' }
#' 
#' @export
write_tableHTML <- function(tableHTML, file, complete_html = FALSE) {
 
 #checks
 if (!inherits(tableHTML, 'tableHTML')) stop('tableHTML needs to be a tableHTML object')
 
 #create style
 if (complete_html) {
  
  tableHTML <- htmltools::HTML(paste('<!DOCTYPE html>\n<html>\n<body>',
                                     tableHTML,
                                     '</body>\n</html>',
                                     sep = '\n'))
  
 }
 
 cat(tableHTML, file = file)
 
 invisible(NULL)
 
}

Try the tableHTML package in your browser

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

tableHTML documentation built on April 18, 2023, 1:11 a.m.