Functions used to convert R code to HTML
This page is a tutorial shows you R functions that assistant in creating a HTML document.
All parameters that will be based to the functions need to be strings ("" or '').
These are a simple functions.
print_newline <- function(){pander::pander("\n")}
It is related to the <br /> that is native to HTML.
pagebreak <- function(){pander::pander('<hr /><div style="clear:both;"></div>')}
It is related to the <hr /> that is native to HTML.
print_h1 <- function(h1){pander::pander(glue::glue("# {h1} \n\n\n"))}
print_h2 <- function(h2){pander::pander(glue::glue("## {h2} \n\n\n"))}
print_h3 <- function(h3){pander::pander(glue::glue("### {h3} \n\n\n"))}
print_h4 <- function(h4){pander::pander(glue::glue("#### {h4} \n\n\n"))}
print_h5 <- function(h5){pander::pander(glue::glue("##### {h5} \n\n\n"))}
print_h6 <- function(h6){pander::pander(glue::glue("###### {h6} \n\n\n"))}
These functions help create headings for the using R. It is related to the <h#>heading</h#> that is native to HTML.
print_pic <- function(img){pander::pander(glue::glue(" \n\n\n"))}
These functions help produce images for the using R. It is related to the <img src = pic> that is native to HTML.
print_link <- function(txt, url){pander::pander(glue::glue("[txt](url) \n\n\n"))}
These functions help produce links for the using R. It is related to the <a href="url">link text</a> that is native to HTML.
print_strong <- function(p){pander::pander(glue::glue('<strong>{p}</strong>'))}
print_bold <- function(p){pander::pander(glue::glue('<b>{p}</b>'))}
print_italic <- function(p){pander::pander(glue::glue('<i>{p}</i>'))}
print_em <- function(p){pander::pander(glue::glue('<em>{p}</em>'))}
print_mark <- function(p){pander::pander(glue::glue('<mark>{p}</mark>'))}
print_small <- function(p){pander::pander(glue::glue('<small>{p}</small>'))}
print_del <- function(p){pander::pander(glue::glue('<del>{p}</del>'))}
print_ins <- function(p){pander::pander(glue::glue('<ins>{p}</ins>'))}
print_sub <- function(p){pander::pander(glue::glue('<sub>{p}</sub>'))}
print_sup <- function(p){pander::pander(glue::glue('<sup>{p}</sup>'))}
HTML contains several elements for defining text with a special meaning. Formatting elements are designed to display special types of text.
javascript_src <- function(source){pander::pander(glue::glue('<script src={source}></script>'))}
javascript_in <- function(fun){pander::pander(glue::glue('<script>{fun}</script>'))}
javascript_no <- funtion(fun, err = "JavaScript not supported"){pander::pander(glue::glue('<script>{fun}</script><noscript>{err}</noscript>'))}
These functions allow you to add javascript to you HTML file using R.
css_src <- function(source){pander::pander(glue::glue('<link rel="stylesheet" href={source}>'))}
css_in <- function(style){pander::pander(glue::glue('<style>{style}</style>'))}
These functions allow you to add styles to you HTML file using R.
For attribution, please cite this work as
Tolliver (2021, March 15). Tolli-Coding: R-HTML. Retrieved from https://tolli-coding.netlify.app/posts/2021-03-15-r-html/
BibTeX citation
@misc{tolliver2021r-html,
author = {Tolliver, Kyle},
title = {Tolli-Coding: R-HTML},
url = {https://tolli-coding.netlify.app/posts/2021-03-15-r-html/},
year = {2021}
}