knitr-knit_hooksset

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

10 Examples 7

19 File: source_file.r, author: klmr, license: MIT License

 .on_load = function(ns) { 

     knitr::knit_hooks$set(box_file = function(before, options,  

         envir) { 

         if (!before) { 

             source_file(options$box_file, options$box_lang) 

         } 

     }) 

 } 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

 knitr::knit_hooks$set(time_it = local({ 

     now  < - NULL 

     function(before, options) { 

         if (before) { 

             now  <  < - Sys.time() 

         } 

         else { 

             res  < - difftime(Sys.time(), now, units = "secs") 

             all_times[[options$label]]  <  < - res 

         } 

     } 

 })) 

19 File: hooks.R, author: nathaneastwood, license: MIT License

 chunk_head  < - function() { 

     knitr::knit_hooks$set(source = function(x, options) { 

         if (!is.null(options$chunk_head) && options$chunk_head) { 

             opts  < - gsub("chunk_head\\s*=\\s*TRUE\\s*", "", do.call("c",  

                 strsplit(options$params.src, ", "))) 

             opts  < - gsub("  ", " ", opts) 

             opts  < - opts[!opts %in% c(" ", "")] 

             opts  < - gsub("^\\s", "", opts) 

             optsList  < - sprintf("%s", opts) 

             bef  < - if (length(opts) != 0 && nchar(opts) > 0) { 

                 paste0("```{r, ", optsList, "}") 

             } 

             else { 

                 "```{r}" 

             } 

             paste0("````md\n", bef, "\n", paste(x, collapse = "\n"),  

                 "\n```\n````\n") 

         } 

         else { 

             paste0("\n\n```", tolower(options$engine), "\n",  

                 paste(x, collapse = "\n"), "\n```\n\n") 

         } 

     }) 

 } 

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

 knitr::knit_hooks$set(optipng = knitr::hook_optipng, pdfcrop = knitr::hook_pdfcrop,  

     small.mar = function(before, options, envir) { 

         if (before)  

             par(mar = c(4.1, 4.1, 0.5, 0.5)) 

     }) 

19 File: _common.R, author: XiangyunHuang, license: MIT License

 knitr::knit_hooks$set(optipng = knitr::hook_optipng, pdfcrop = knitr::hook_pdfcrop,  

     small.mar = function(before, options, envir) { 

         if (before)  

             par(mar = c(4.1, 4.1, 0.5, 0.5)) 

     }) 

Categories r Tags