knitr-is_latex_output

Here are the examples of the r api knitr-is_latex_output taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

 kable  < - function(x, format, digits = getOption("digits"), row.names = NA,  

     col.names = NA, align, caption = NULL, label = NULL, format.args = list(),  

     escape = TRUE, ...) { 

     knitr::kable(x = x, digits = digits, row.names = row.names,  

         col.names = col.names, caption = if (knitr::is_latex_output())  

             commonmark::markdown_latex(caption) 

         else caption, label = label, format.args = format.args,  

         escape = escape, ...) 

 } 

 kbl  < - function(x, format, digits = getOption("digits"), row.names = NA,  

     col.names = NA, align, caption = NULL, label = NULL, format.args = list(),  

     escape = TRUE, table.attr = "", booktabs = FALSE, longtable = FALSE,  

     valign = "t", position = "", centering = TRUE, vline = getOption("knitr.table.vline",  

         if (booktabs) "" else "|"), toprule = getOption("knitr.table.toprule",  

         if (booktabs) "\\toprule" else "\\hline"), bottomrule = getOption("knitr.table.bottomrule",  

         if (booktabs) "\\bottomrule" else "\\hline"), midrule = getOption("knitr.table.midrule",  

         if (booktabs) "\\midrule" else "\\hline"), linesep = if (booktabs) c("",  

         "", "", "", "\\addlinespace") else "\\hline", caption.short = "",  

     table.envir = if (!is.null(caption)) "table", ...) { 

     if ("kableExtra" %in% installed.packages()) { 

         kableExtra::kbl(x = x, digits = digits, row.names = row.names,  

             col.names = col.names, caption = if (knitr::is_latex_output())  

                 commonmark::markdown_latex(caption) 

             else caption, label = label, format.args = format.args,  

             escape = escape, table.attr = table.attr, booktabs = booktabs,  

             longtable = longtable, valign = valign, position = position,  

             centering = centering, vline = vline, toprule = toprule,  

             bottomrule = bottomrule, midrule = midrule, linesep = linesep,  

             caption.short = caption.short, table.envir = table.envir,  

             ...) 

     } 

     else { 

         stop("package `kableExtra` not found.") 

     } 

 } 

 ruby  < - function(word, ruby) { 

     if (knitr::is_html_output()) { 

         paste0("` < ruby>", word, " < rp>( < /rp> < rt>", ruby, " < /rt> < rp>) < /rp> < /ruby>`{=html}") 

     } 

     else if (knitr::is_latex_output()) { 

         paste0("`\\ruby[g]{", word, "}{", ruby, "}`{=latex}") 

     } 

     else { 

         paste0(word, " (", ruby, ")") 

     } 

 } 

 texlogo  < - function(logoname, as_markdown = F) { 

     base  < - switch(tolower(logoname), tex = "TeX", amslatex = "AmSLaTeX",  

         amstex = "AmSTeX", bibtex = "BibTeX", context = "ConTeXt",  

         etex = "eTeX", latex = "LaTeX", latexe = "LaTeXe", lualatex = "LuaLaTeX",  

         luatex = "LuaTeX", lyx = "LyX", metafont = "METAFONT",  

         meapost = "METAPOST", pdftex = "pdfTeX", pdflatex = "pdfLaTeX",  

         xelatex = "XeLaTeX", xetex = "XeTeX", epTeX = "e-PTeX",  

         euptex = "eupTeX", jbibtex = "JBibTeX", pbibtex = "pBibTeX",  

         platexe = "pLaTeXe", platex = "pLaTeX", ptex = "pTeX",  

         tikz = "TikZ", upbibtex = "upBibTeX", uplatex = "upLaTeX",  

         uplatexe = "upLaTeXe", uptex = "upTeX", hanthethanh = "HanTheThanh",  

         komascript = "KOMAScript", latextex = "LaTeXTeX", nts = "NTS",  

         pictex = "PiCTeX", sagetex = "SageTeX", slitex = "SLiTeX",  

         tetex = "teTeX", tth = "TTH", aptex = "ApTeX", hevea = "HeVeA",  

         jbibtex = "JBibTeX", jlatex = "JLaTeX", jtex = "JTeX",  

         katex = "KaTeX", ket = "KET", ketpic = "KETpic", latexit = "LaTeXiT",  

         latexml = "LaTeXML", logoaleph = "logoAleph", logolambda = "logoLambda",  

         logolamed = "logoLamed", logoomega = "logoOmega", ptexst = "pTeXsT",  

         xym = "XyM", xymtex = "XyMTeX", "") 

     if (nchar(base) == 0) { 

         r  < - logoname 

     } 

     else { 

         if (as_markdown) { 

             r  < - paste0("`\\", base, "`{=latex}`", base, "`{=html}") 

         } 

         else { 

             r  < - if (knitr::is_latex_output())  

                 paste0("\\", base) 

             else base 

         } 

     } 

     return(r) 

 } 

19 File: fun.R, author: pzhaonet, license: MIT License

 include_image  < - function(img_url, img_dir = "images") { 

     if (knitr::is_latex_output()) { 

         file_name  < - basename(img_url) 

         img_local  < - file.path(img_dir, file_name) 

         if (!file.exists(img_local))  

             download.file(img_url, img_local, mode = "wb") 

         if (grepl("\\.gif$", img_local)) { 

             giffile  < - magick::image_read(img_local) 

             img_new  < - gsub("\\.gif$", "\\.png", img_local) 

             magick::image_write(magick::image_convert(giffile,  

                 format = "png"), img_new) 

             img_local  < - img_new 

         } 

         knitr::include_graphics(img_local) 

     } 

     else { 

         knitr::include_graphics(img_url) 

     } 

 } 

19 File: sp_print_df.R, author: smithjd, license: MIT License

 sp_print_df  < - function(df) { 

     if (knitr::is_latex_output()) { 

         knitr::kable(df) 

     } 

     else { 

         DT::datatable(df) 

     } 

 } 

Categories r Tags