[rkward] rkward/rbackend/rpackages/rkward: Better example for custom preview
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Jan 26 17:14:20 UTC 2016
Git commit ef65b7087cac890e5909dc862d284274a44d2d4b by Thomas Friedrichsmeier.
Committed on 26/01/2016 at 17:14.
Pushed by tfry into branch 'master'.
Better example for custom preview
M +10 -9 rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
M +10 -9 rkward/rbackend/rpackages/rkward/man/rk.assign.preview.data.Rd
M +2 -1 rkward/rbackend/rpackages/rkward/man/rk.results.Rd
http://commits.kde.org/rkward/ef65b7087cac890e5909dc862d284274a44d2d4b
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index 5093d39..f55ce0c 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -212,17 +212,18 @@ assign(".rk.preview.data", list (), envir=.rk.variables)
#' ## To be generated in the preview() code section of a plugin
#'
#' ## NOT RUN
-#' outfile <- rk.get.tempfile.name(prefix="preview", extension=".html")
-#' rk.assign.preview.data("SOMEID", list(filename=outfile, on.delete=function (id) {
-#' unlink(rk.get.preview.data(id)$filename)
-#' }))
-#' oldfile <- rk.set.output.html.file(f)
+#' pdata <- rk.get.preview.data("SOMEID")
+#' if (is.null (pdata)) {
+#' outfile <- rk.get.tempfile.name(prefix="preview", extension=".txt")
+#' pdata <- list(filename=outfile, on.delete=function (id) {
+#' unlink(rk.get.preview.data(id)$filename)
+#' })
+#' rk.assign.preview.data("SOMEID", pdata)
+#' }
#' try ({
-#' rk.header("This is a preview of what will happen")
-#' rk.show.html(rk.get.output.html.file())
-#' rk.flush.output()
+#' cat ("This is a test", pdata$filename)
+#' rk.edit.files(file=pdata$filename)
#' })
-#' rk.set.output.html.file(outfile)
#' ## END NOT RUN
#'
#' @export
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.assign.preview.data.Rd b/rkward/rbackend/rpackages/rkward/man/rk.assign.preview.data.Rd
index 47d6150..0d306c0 100644
--- a/rkward/rbackend/rpackages/rkward/man/rk.assign.preview.data.Rd
+++ b/rkward/rbackend/rpackages/rkward/man/rk.assign.preview.data.Rd
@@ -40,17 +40,18 @@ code, such as removing temporary files, etc.}
## To be generated in the preview() code section of a plugin
## NOT RUN
-outfile <- rk.get.tempfile.name(prefix="preview", extension=".html")
-rk.assign.preview.data("SOMEID", list(filename=outfile, on.delete=function (id) {
- unlink(rk.get.preview.data(id)$filename)
-}))
-oldfile <- rk.set.output.html.file(f)
+pdata <- rk.get.preview.data("SOMEID")
+if (is.null (pdata)) {
+ outfile <- rk.get.tempfile.name(prefix="preview", extension=".txt")
+ pdata <- list(filename=outfile, on.delete=function (id) {
+ unlink(rk.get.preview.data(id)$filename)
+ })
+ rk.assign.preview.data("SOMEID", pdata)
+}
try ({
- rk.header("This is a preview of what will happen")
- rk.show.html(rk.get.output.html.file())
- rk.flush.output()
+ cat ("This is a test", pdata$filename)
+ rk.edit.files(file=pdata$filename)
})
-rk.set.output.html.file(outfile)
## END NOT RUN
}
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.results.Rd b/rkward/rbackend/rpackages/rkward/man/rk.results.Rd
index 5c1689f..2635516 100644
--- a/rkward/rbackend/rpackages/rkward/man/rk.results.Rd
+++ b/rkward/rbackend/rpackages/rkward/man/rk.results.Rd
@@ -61,7 +61,8 @@ Output. Basically, these functions along with the ones described in
\code{rk.print} prints/exports the given object to the output (html) file
using the \code{\link{HTML}} function. This requires the \code{R2HTML}
package. Additional arguments in \code{...} are passed on to
-\code{\link{HTML}}.
+\code{\link{HTML}}. For some types of objects (e.g. "htmlwidgets" from
+the "htmlwidgets" package) additional packages may be required.
\code{rk.print.literal} prints/exports the given object using a
\code{paste(x, collapse="\n")} construct to the output (html) file.
More information about the rkward-tracker
mailing list