knitr.R 636 B

123456789101112131415161718192021
  1. #' @export
  2. knitr_language_engine <- function(llr_interpreter = llr_env$new()) {
  3. if (!requireNamespace("knitr", quietly = TRUE)) {
  4. stop("kntir is required to use this function")
  5. }
  6. function(options) {
  7. code <- paste(options$code, collapse = "\n")
  8. if (!options$eval) {
  9. knitr::engine_output(options, options$code, NULL)
  10. } else {
  11. result <- llr_interpreter$eval(code)
  12. if (options$results == "hide") {
  13. knitr::engine_output(options, options$code, NULL)
  14. } else {
  15. out <- utils::capture.output(print(result))
  16. knitr::engine_output(options, options$code, out)
  17. }
  18. }
  19. }
  20. }