[rkward/work/render_rmd] rkward/windows: Render preview now uses rmarkdown package (to allow rendering of v2). Includes check for pandoc.

Thomas Friedrichsmeier null at kde.org
Thu Sep 27 11:16:27 BST 2018


Git commit 4377752fa188d821f7ba244f7fdb7f9f872d7f5b by Thomas Friedrichsmeier.
Committed on 27/09/2018 at 10:14.
Pushed by tfry into branch 'work/render_rmd'.

Render preview now uses rmarkdown package (to allow rendering of v2). Includes check for pandoc.

M  +17   -6    rkward/windows/rkcommandeditorwindow.cpp

https://commits.kde.org/rkward/4377752fa188d821f7ba244f7fdb7f9f872d7f5b

diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index dbb55491..637c8f1c 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -804,12 +804,22 @@ void RKCommandEditorWindow::doRenderPreview () {
 		save.close ();
 		save.setAutoRemove (false);
 
-		QString command ("require(knitr)\n"
-				"require(markdown)\n"
-				"rk.show.html (knitr::knit2html(%1, quiet=TRUE))");
-		command = command.arg (RObject::rQuote (save.fileName ()));
-
-		RCommand *rcommand = new RCommand (".rk.with.window.hints ({\n" + command + QStringLiteral ("}, \"\", ") + RObject::rQuote (preview_manager->previewId ()) + ')', RCommand::App);
+		QString command ("if (!nzchar(Sys.which(\"pandoc\"))) {\n"
+		                 "	output <- rk.set.output.html.file(%2)\n"
+		                 "	rk.header (" + RObject::rQuote (i18n ("Pandoc is not installed")) + ")\n"
+		                 "	rk.print (" + RObject::rQuote (i18n ("The software <tt>pandoc</tt>, required ot rendering R markdown files, is not installed, or not in the system path of "
+		                           "the running R session. You will need to install pandoc from <a href=\"https://pandoc.org/\">https://pandoc.org/</a>.</br>"
+		                           "If is installed, but cannot be found, try adding it to the system path of the running R session at "
+		                           "<a href=\"rkward://settings/rbackend\">Settings->Configure RKward->R-backend</a>.")) + ")\n"
+		                 "	rk.set.output.html.file(output)\n"
+		                 "} else {\n"
+		                 "	require(rmarkdown)\n"
+		                 "	rmarkdown::render (%1, output_format=\"html_document\", output_file=%2, quiet=TRUE)\n"
+		                 "}\n"
+		                 "rk.show.html(%2)\n");
+		command = command.arg (RObject::rQuote (save.fileName ()), RObject::rQuote (save.fileName () + ".html"));
+
+		RCommand *rcommand = new RCommand (".rk.with.window.hints (local ({\n" + command + QStringLiteral ("}), \"\", ") + RObject::rQuote (preview_manager->previewId ()) + ')', RCommand::App);
 		preview_manager->setCommand (rcommand);
 		preview->wrapperWidget ()->show ();
 	}
@@ -1369,3 +1379,4 @@ void RKCommandHighlighter::copyLinesToOutput (KTextEditor::View *view, Highlight
 	}
 }
 
+



More information about the rkward-tracker mailing list