From 9a89444127df69760220939d67b2f332237d01dd Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 29 Jul 2016 12:37:21 +0200 Subject: [PATCH] Added examples and a few doc links --- R/display.r | 19 +++++++++++++++++-- R/display_images.r | 10 ++++++++++ R/display_textual.r | 6 ++++++ R/options.r | 2 +- man/IRdisplay-options.Rd | 2 +- man/display.Rd | 10 +++++++++- man/display_-less-than-image-greater-than.Rd | 11 +++++++++++ man/display_-less-than-text-greater-than.Rd | 7 +++++++ man/publish_mimebundle.Rd | 10 +++++++++- 9 files changed, 71 insertions(+), 6 deletions(-) diff --git a/R/display.r b/R/display.r index 70c4a55..fb6ac60 100644 --- a/R/display.r +++ b/R/display.r @@ -1,11 +1,18 @@ #' Display data by mimetype, with optional alternative representations. #' -#' Calls the function stored as option value of \code{jupyter.base_display_func}. +#' Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) #' #' @param data A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors}) #' @param metadata A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))} #' #' @seealso \code{\link{prepare_mimebundle}} +#' +#' @examples \dontrun{## (Run inside of an IRkernel) +#' publish_mimebundle(list('text/html' = '

Hi!

')) +#' publish_mimebundle( +#' list('image/svg+xml' = ''), +#' list('image/svg+xml' = list(width = 100, height = 100)))} +#' #' @export publish_mimebundle <- function(data, metadata = NULL) { getOption('jupyter.base_display_func')(data, metadata) @@ -18,13 +25,21 @@ publish_mimebundle <- function(data, metadata = NULL) { #' \code{prepare_mimebundle} returns it (see \emph{Value} for details) #' #' @param obj The object to create representations for -#' @param mimetypes Mimetypes to create reprs for +#' @param mimetypes Mimetypes to create reprs for. The defaults are defined by the option \code{jupyter.display_mimetypes}. (see: \link{IRdisplay-options}) #' @param metadata Metadata to attach to the result (can be expanded by additional metadata) #' @param error_handler Function used when errors in individual reprs occur #' #' @return \code{prepare_mimebundle} returns a list with items corresponding to the parameters of \code{\link{publish_mimebundle}} (\code{data} and \code{metadata}) #' #' @seealso \code{\link{publish_mimebundle}} +#' +#' @examples +#' dev.new(); plot(sqrt); p <- recordPlot(); dev.off() +#' bundle <- prepare_mimebundle(p) +#' +#' \dontrun{## (Run inside of an IRkernel) +#' display(help(display))} +#' #' @name display #' @export display <- function(obj) { diff --git a/R/display_images.r b/R/display_images.r index 490c7f0..f233888 100644 --- a/R/display_images.r +++ b/R/display_images.r @@ -8,6 +8,16 @@ #' @param height The height to display the image #' #' @seealso \code{\link{display_}} +#' +#' @examples \dontrun{## (Run inside of an IRkernel) +#' display_png(file = 'image.png') +#' display_svg(' +#' +#' +#' +#' ') +#' display_jpeg(file = url('http://example.com/example.jpg'), width = 100)} +#' #' @name display_ NULL diff --git a/R/display_textual.r b/R/display_textual.r index edbdea4..43d2b31 100644 --- a/R/display_textual.r +++ b/R/display_textual.r @@ -6,6 +6,12 @@ #' @param file The path to a file or a \code{\link[base]{connection}} containing the content #' #' @seealso \code{\link{display_}} +#' +#' @examples \dontrun{## (Run inside of an IRkernel) +#' display_text('Just text') +#' display_markdown('[MD](http://commonmark.org) *formatted*') +#' display_javascript('execute(this)')} +#' #' @name display_ NULL diff --git a/R/options.r b/R/options.r index 43994a5..0be14d3 100644 --- a/R/options.r +++ b/R/options.r @@ -1,6 +1,6 @@ #' IRdisplay options #' -#' Options to control the formats \code{\link{display}} and \code{\link{prepare_mimebundle}} emit, +#' Some \link{options} to control the formats \code{\link{display}} and \code{\link{prepare_mimebundle}} emit, #' and the function they use to display them. #' #' @section Options: diff --git a/man/IRdisplay-options.Rd b/man/IRdisplay-options.Rd index e4be4b6..c0e4b15 100644 --- a/man/IRdisplay-options.Rd +++ b/man/IRdisplay-options.Rd @@ -10,7 +10,7 @@ irdisplay_option_defaults } \description{ -Options to control the formats \code{\link{display}} and \code{\link{prepare_mimebundle}} emit, +Some \link{options} to control the formats \code{\link{display}} and \code{\link{prepare_mimebundle}} emit, and the function they use to display them. } \section{Options}{ diff --git a/man/display.Rd b/man/display.Rd index dea38e3..32423c4 100644 --- a/man/display.Rd +++ b/man/display.Rd @@ -13,7 +13,7 @@ prepare_mimebundle(obj, mimetypes = getOption("jupyter.display_mimetypes"), \arguments{ \item{obj}{The object to create representations for} -\item{mimetypes}{Mimetypes to create reprs for} +\item{mimetypes}{Mimetypes to create reprs for. The defaults are defined by the option \code{jupyter.display_mimetypes}. (see: \link{IRdisplay-options})} \item{metadata}{Metadata to attach to the result (can be expanded by additional metadata)} @@ -26,6 +26,14 @@ prepare_mimebundle(obj, mimetypes = getOption("jupyter.display_mimetypes"), Both functions create a mimebundle for multiple reprs. \code{display} proceeds to publish it using \code{\link{publish_mimebundle}}. \code{prepare_mimebundle} returns it (see \emph{Value} for details) +} +\examples{ +dev.new(); plot(sqrt); p <- recordPlot(); dev.off() +bundle <- prepare_mimebundle(p) + +\dontrun{## (Run inside of an IRkernel) +display(help(display))} + } \seealso{ \code{\link{publish_mimebundle}} diff --git a/man/display_-less-than-image-greater-than.Rd b/man/display_-less-than-image-greater-than.Rd index 2132cd7..db50286 100644 --- a/man/display_-less-than-image-greater-than.Rd +++ b/man/display_-less-than-image-greater-than.Rd @@ -27,6 +27,17 @@ display_svg(data = NULL, file = NULL, width = NULL, height = NULL) } \description{ Either \code{data} or \code{file} must be passed. +} +\examples{ +\dontrun{## (Run inside of an IRkernel) +display_png(file = 'image.png') +display_svg(' + + + +') +display_jpeg(file = url('http://example.com/example.jpg'), width = 100)} + } \seealso{ \code{\link{display_}} diff --git a/man/display_-less-than-text-greater-than.Rd b/man/display_-less-than-text-greater-than.Rd index 093b0be..d41fe91 100644 --- a/man/display_-less-than-text-greater-than.Rd +++ b/man/display_-less-than-text-greater-than.Rd @@ -26,6 +26,13 @@ display_latex(data = NULL, file = NULL) } \description{ Either \code{data} or \code{file} must be passed. +} +\examples{ +\dontrun{## (Run inside of an IRkernel) +display_text('Just text') +display_markdown('[MD](http://commonmark.org) *formatted*') +display_javascript('execute(this)')} + } \seealso{ \code{\link{display_}} diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd index e52b627..bb67c21 100644 --- a/man/publish_mimebundle.Rd +++ b/man/publish_mimebundle.Rd @@ -12,7 +12,15 @@ publish_mimebundle(data, metadata = NULL) \item{metadata}{A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))}} } \description{ -Calls the function stored as option value of \code{jupyter.base_display_func}. +Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) +} +\examples{ +\dontrun{## (Run inside of an IRkernel) +publish_mimebundle(list('text/html' = '

Hi!

')) +publish_mimebundle( + list('image/svg+xml' = ''), + list('image/svg+xml' = list(width = 100, height = 100)))} + } \seealso{ \code{\link{prepare_mimebundle}}