IRdisplay/0000755000176200001440000000000014165034450012154 5ustar liggesusersIRdisplay/NAMESPACE0000644000176200001440000000072214165001723013371 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(clear_output) export(display) export(display_html) export(display_javascript) export(display_jpeg) export(display_json) export(display_latex) export(display_markdown) export(display_pdf) export(display_png) export(display_svg) export(display_text) export(irdisplay_option_defaults) export(prepare_mimebundle) export(publish_mimebundle) importFrom(methods,is) importFrom(repr,mime2repr) importFrom(stats,setNames) IRdisplay/LICENSE0000644000176200001440000000011113276103154013152 0ustar liggesusersYEAR: 2014 COPYRIGHT HOLDER: Thomas Kluyver, Philipp Angerer, Jan Schulz IRdisplay/README.md0000644000176200001440000000347414164775343013457 0ustar liggesusersIRdisplay [![b-CI]][CI] [![b-CRAN]][CRAN] ========= [b-CI]: https://github.com/IRkernel/IRdisplay/actions/workflows/r.yml/badge.svg?branch=master "Build status" [CI]: https://github.com/IRkernel/IRdisplay/actions/workflows/r.yml [b-CRAN]: https://www.r-pkg.org/badges/version/IRdisplay "Comprehensive R Archive Network" [CRAN]: https://cran.r-project.org/package=IRdisplay IRdisplay is a front-end package for Jupyter. It’s automatically integrated into [IRkernel][] when you open a Jupyter notebook using that kernel. The primary, high level functions are: ```r display(obj, ..., mimetypes=, error_handler=stop) display_png(data = NULL, file = NULL, width = NULL, height = NULL) # display_jpeg(…); display_pdf(…); display_svg(…) display_html(data = NULL, file = NULL) # display_javascript(…), display_json(…), display_markdown(…), display_latex(…) ``` Use `display` to display an object in all configured mime types (see **Configuration**), and the `display_*` functions to display raw data you have in form of a file or a variable. Manual use is possible via the `*_mimebundle` functions: ```r prepare_mimebundle(obj, mimetypes=, metadata=NULL, error_handler=stop) publish_mimebundle(data, metadata = NULL) ``` Where `prepare_mimebundle` uses `repr` to create a mimebundle containing representations of objects, and `publish_mimebundle` sends such mimebundles to Jupyter. [IRkernel]: https://irkernel.github.io/running/ Configuration ------------- You can add your own mime types that should be displayed via: ```r options(jupyter.display_mimetypes = union(getOption('jupyter.display_mimetypes'), ...)) ``` If you want to create your own kernel reacting to `display` / `publish_mimebundle` calls, you can use: ```r options(jupyter.base_display_func = function(data, metadata = NULL) ...) ``` IRdisplay/man/0000755000176200001440000000000014165001607012725 5ustar liggesusersIRdisplay/man/IRdisplay-options.Rd0000644000176200001440000000221114165001607016601 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/options.r \docType{data} \name{IRdisplay-options} \alias{IRdisplay-options} \alias{irdisplay_option_defaults} \title{IRdisplay options} \format{ An object of class \code{list} of length 3. } \usage{ irdisplay_option_defaults } \description{ 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}{ \describe{ \item{\code{jupyter.display_mimetypes}}{ The default is all MIME types supported by Jupyter. } \item{\code{jupyter.base_display_func}}{ Function used by \code{\link{display}} and all \code{\link{display_}} / \code{\link{display_}} functions. Has the signature \code{function(data, metadata = NULL)}. Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. } \item{\code{jupyter.clear_output_func}}{ Function used by \code{\link{clear_output}}. Has the signature \code{function(wait = TRUE)}. Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. } } } \keyword{datasets} IRdisplay/man/display-images.Rd0000644000176200001440000000233413601141377016131 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/display_images.r \name{display_} \alias{display_} \alias{display_png} \alias{display_jpeg} \alias{display_pdf} \alias{display_svg} \title{Display a specific image output} \usage{ display_png(data = NULL, file = NULL, width = NULL, height = NULL) display_jpeg(data = NULL, file = NULL, width = NULL, height = NULL) display_pdf(data = NULL, file = NULL, width = NULL, height = NULL) display_svg(data = NULL, file = NULL, width = NULL, height = NULL) } \arguments{ \item{data}{The data as a \code{\link[base]{raw}} vector (\code{\link[base]{character}} vector for \code{display_svg})} \item{file}{The path to a file or a \code{\link[base]{connection}} containing the content} \item{width}{The width to display the image} \item{height}{The height to display the image} } \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('https://dummyimage.com/600x400.jpg', 'wb'), width = 100)} } \seealso{ \code{\link{display_}} } IRdisplay/man/publish_mimebundle.Rd0000644000176200001440000000313014165001607017060 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/display.r \name{publish_mimebundle} \alias{publish_mimebundle} \alias{clear_output} \title{Display data by mimetype, with optional alternative representations.} \usage{ publish_mimebundle(data, metadata = NULL) clear_output(wait = TRUE) } \arguments{ \item{data}{A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors})} \item{metadata}{A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))}} \item{wait}{Wait to clear the output until new output is available. Default \code{TRUE}. If \code{FALSE}, clears the existing output immediately before the new output is displayed.} } \description{ \code{publish_mimebundle} calls the function stored as option value of \code{jupyter.base_display_func}, \code{clear_output} calls the value of option \code{jupyter.clear_output_func}. (see: \link{IRdisplay-options}) } \section{Functions}{ \itemize{ \item \code{clear_output}: Clear the output from the current cell. }} \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))) for (i in 1:5) { Sys.sleep(.2) # simulate work clear_output() # clear previous iteration cat(i) # alternative: IRdisplay::display(i) flush.console() # make output available }} } \seealso{ \code{\link{prepare_mimebundle}} } IRdisplay/man/display-textual.Rd0000644000176200001440000000203514002106336016340 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/display_textual.r \name{display_} \alias{display_} \alias{display_text} \alias{display_json} \alias{display_javascript} \alias{display_html} \alias{display_markdown} \alias{display_latex} \title{Display a specific textual output} \usage{ display_text(data = NULL, file = NULL) display_json(data = NULL, file = NULL) display_javascript(data = NULL, file = NULL) display_html(data = NULL, file = NULL) display_markdown(data = NULL, file = NULL) display_latex(data = NULL, file = NULL) } \arguments{ \item{data}{The code or markup content as a \code{\link[base]{character}} vector} \item{file}{The path to a file or a \code{\link[base]{connection}} containing the content} } \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_}} } IRdisplay/man/display.Rd0000644000176200001440000000253114002106336014655 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/display.r \name{display} \alias{display} \alias{prepare_mimebundle} \title{Create and use multiple available reprs} \usage{ display( obj, ..., mimetypes = getOption("jupyter.display_mimetypes"), error_handler = stop ) prepare_mimebundle( obj, mimetypes = getOption("jupyter.display_mimetypes"), metadata = NULL, error_handler = stop ) } \arguments{ \item{obj}{The object to create representations for} \item{mimetypes}{Mimetypes to create reprs for. The defaults are defined by the option \code{jupyter.display_mimetypes}. (see: \link{IRdisplay-options})} \item{error_handler}{Function used when errors in individual reprs occur} \item{metadata, ...}{Metadata to attach to the result (can be expanded by additional metadata)} } \value{ \code{prepare_mimebundle} returns a list with items corresponding to the parameters of \code{\link{publish_mimebundle}} (\code{data} and \code{metadata}) } \description{ 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{ bundle <- prepare_mimebundle(diag(3)) \dontrun{## (Run inside of an IRkernel) display(help(display))} } \seealso{ \code{\link{publish_mimebundle}} } IRdisplay/DESCRIPTION0000644000176200001440000000221314165034450013660 0ustar liggesusersPackage: IRdisplay Title: 'Jupyter' Display Machinery Description: An interface to the rich display capabilities of 'Jupyter' front-ends (e.g. 'Jupyter Notebook') . Designed to be used from a running 'IRkernel' session . Version: 1.1 Authors@R: c( person('Thomas', 'Kluyver', role = c('aut', 'cph'), email = 'thomas@kluyver.me.uk'), person('Philipp', 'Angerer', role = c('aut', 'cph', 'cre'), email = 'phil.angerer@gmail.com', comment = c(ORCID = "0000-0002-0369-2888")), person('Jan', 'Schulz', role = c('aut', 'cph'), email = 'jasc@gmx.net')) URL: https://github.com/IRkernel/IRdisplay BugReports: https://github.com/IRkernel/IRdisplay/issues/ Depends: R (>= 3.0.1) Suggests: testthat, withr Imports: methods, repr License: MIT + file LICENSE Encoding: UTF-8 RoxygenNote: 7.1.2 NeedsCompilation: no Packaged: 2022-01-04 08:22:43 UTC; phil Author: Thomas Kluyver [aut, cph], Philipp Angerer [aut, cph, cre] (), Jan Schulz [aut, cph] Maintainer: Philipp Angerer Repository: CRAN Date/Publication: 2022-01-04 12:10:16 UTC IRdisplay/tests/0000755000176200001440000000000013276103154013316 5ustar liggesusersIRdisplay/tests/testthat/0000755000176200001440000000000014165034450015156 5ustar liggesusersIRdisplay/tests/testthat/test-options.r0000644000176200001440000000021513400224401017773 0ustar liggesuserscontext('default options') test_that('default options are set', { expect_equal(length(getOption('jupyter.display_mimetypes')), 15L) }) IRdisplay/tests/testthat/test_display_functions_textual.r0000644000176200001440000000262613276103154023711 0ustar liggesuserscontext('textual display functions') last_data <- NULL test_display_func <- function(data, metadata = NULL) { last_data <<- list(data, metadata) } get_last_data <- function() { ret <- last_data last_data <<- NULL ret } withr::with_options(list(jupyter.base_display_func = test_display_func), { test_that('display_json works', { exp <- list('application/json' = '{}') display_json('{}') expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display_javascript works', { exp <- list('application/javascript' = 'data') display_javascript('data') expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display_html works', { exp <- list('text/html' = 'data') display_html('data') expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display_html with full html page', { exp <- list('text/html' = 'text') exp_md <- list('text/html' = list(isolated = TRUE)) display_html('text') expect_equal(get_last_data(), list(exp, exp_md)) }) test_that('display_markdown works', { exp <- list('text/markdown' = 'data') display_markdown('data') expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display_latex works', { exp <- list('text/latex' = 'data') display_latex('data') expect_equal(get_last_data(), list(exp, NULL)) }) }) IRdisplay/tests/testthat/test_display_functions_images.r0000644000176200001440000000250513601141377023465 0ustar liggesuserscontext('image display functions') last_data <- NULL test_display_func <- function(data, metadata = NULL) { last_data <<- list(data, metadata) } get_last_data <- function() { ret <- last_data last_data <<- NULL ret } withr::with_options(list(jupyter.base_display_func = test_display_func), { test_that('display_png works', { dta <- as.raw(1:3) exp <- list('image/png' = dta) exp_md <- list('image/png' = list(width = 1, height = 2)) display_png(dta) expect_equal(get_last_data(), list(exp, NULL)) display_png(dta, width = 1, height = 2) expect_equal(get_last_data(), list(exp, exp_md)) }) test_that('display_jpeg works', { dta <- as.raw(1:3) exp <- list('image/jpeg' = dta) exp_md <- list('image/jpeg' = list(width = 1, height = 2)) display_jpeg(dta) expect_equal(get_last_data(), list(exp, NULL)) display_jpeg(dta, width = 1, height = 2) expect_equal(get_last_data(), list(exp, exp_md)) }) test_that('display_pdf works', { dta <- as.raw(1:3) exp <- list('application/pdf' = dta) display_pdf(dta) expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display_svg works', { exp <- list('image/svg+xml' = '') display_svg('') expect_equal(get_last_data(), list(exp, NULL)) }) }) IRdisplay/tests/testthat/test_display_functions.r0000644000176200001440000000542713377251200022143 0ustar liggesuserscontext('general display functions') library(repr) last_data <- NULL test_display_func <- function(data, metadata = NULL) { last_data <<- list(data, metadata) } get_last_data <- function() { ret <- last_data last_data <<- NULL ret } test_that('display without a jupyter.base_display_func raises a warning', { expect_warning(display(NULL), regexp = 'can only be used from') }) withr::with_options(list(jupyter.base_display_func = test_display_func), { test_that('publish_mimebundle works', { publish_mimebundle(NULL) expect_equal(get_last_data(), list(NULL, NULL)) publish_mimebundle(1, 1) expect_equal(get_last_data(), list(1, 1)) }) test_that('display works', { # NULL only displays in text/plain exp <- list('text/plain' = repr_text(NULL)) display(NULL) expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display only creates the jupyter.display_mimetypes', { exp <- list( 'text/plain' = repr_text(1), 'text/html' = repr_html(1)) withr::with_options( list(jupyter.display_mimetypes = c('text/plain', 'text/html')), display(1)) expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display attaches metadata', { exp <- list( 'text/plain' = 'x', 'text/html' = 'x') exp_md <- list('text/html' = list(isolated = TRUE)) withr::with_options(list(jupyter.display_mimetypes = c('text/plain', 'text/html')), { .GlobalEnv$repr_text.html_literal <- .GlobalEnv$repr_html.html_literal <- function(obj, ...) unclass(obj) display(structure('x', class = 'html_literal')) }) expect_equal(get_last_data(), list(exp, exp_md)) }) test_that('display handles raw data', { dta <- as.raw(1:10) exp <- list( 'text/plain' = 'PNG data: 01 02 03 04 05...', 'image/png' = dta) withr::with_options(list(jupyter.display_mimetypes = c('text/plain', 'image/png')), { .GlobalEnv$repr_text.raw_png <- function(obj, ...) sprintf('PNG data: %s...', paste(obj[1:5], collapse = ' ')) .GlobalEnv$repr_png.raw_png <- function(obj, ...) unclass(obj) display(structure(dta, class = 'raw_png')) }) expect_equal(get_last_data(), list(exp, NULL)) }) test_that('display needs > 0 display_mimetypes', { withr::with_options( list(jupyter.display_mimetypes = character(0L)), expect_error(display(1), 'may not be NULL or of length 0')) withr::with_options( list(jupyter.display_mimetypes = NULL), expect_error(display(1), 'may not be NULL or of length 0')) }) test_that('display_raw works', { exp <- list('text/plain' = 'data') display_raw('text/plain', FALSE, 'data', NULL) expect_equal(get_last_data(), list(exp, NULL)) }) }) IRdisplay/tests/testthat/test_base_display.r0000644000176200001440000000031413276103154021035 0ustar liggesuserscontext('jupyter.base_display_func') test_that('original jupyter.base_display_func raises a warning', { expect_warning(getOption('jupyter.base_display_func')(NULL), regexp = 'can only be used from') }) IRdisplay/tests/testthat.R0000644000176200001440000000007613276103154015304 0ustar liggesuserslibrary(testthat) library(IRdisplay) test_check('IRdisplay') IRdisplay/R/0000755000176200001440000000000014165001607012353 5ustar liggesusersIRdisplay/R/display.r0000644000176200001440000001126214165001607014205 0ustar liggesusers#' Display data by mimetype, with optional alternative representations. #' #' \code{publish_mimebundle} calls the function stored as option value of \code{jupyter.base_display_func}, #' \code{clear_output} calls the value of option \code{jupyter.clear_output_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))} #' @param wait Wait to clear the output until new output is available. Default \code{TRUE}. #' If \code{FALSE}, clears the existing output immediately before the new output is displayed. #' #' @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))) #' #' for (i in 1:5) { #' Sys.sleep(.2) # simulate work #' clear_output() # clear previous iteration #' cat(i) # alternative: IRdisplay::display(i) #' flush.console() # make output available #' }} #' #' @export publish_mimebundle <- function(data, metadata = NULL) { getOption('jupyter.base_display_func')(data, metadata) } #' @describeIn publish_mimebundle Clear the output from the current cell. #' @export clear_output <- function(wait = TRUE) { getOption('jupyter.clear_output_func')(wait) } #' Create and use multiple available reprs #' #' 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) #' #' @param obj The object to create representations 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 #' bundle <- prepare_mimebundle(diag(3)) #' #' \dontrun{## (Run inside of an IRkernel) #' display(help(display))} #' #' @name display #' @export display <- function( obj, ..., mimetypes = getOption('jupyter.display_mimetypes'), error_handler = stop ) { metadata <- list(...) if (length(metadata) == 0L) metadata <- NULL bundle <- prepare_mimebundle(obj, mimetypes, metadata, error_handler) publish_mimebundle(bundle$data, bundle$metadata) } #' @importFrom repr mime2repr #' @rdname display #' @export prepare_mimebundle <- function( obj, mimetypes = getOption('jupyter.display_mimetypes'), metadata = NULL, error_handler = stop ) { if (length(mimetypes) == 0L) stop('option jupyter.display_mimetypes may not be NULL or of length 0') outer_handler <- if (identical(error_handler, stop)) stop else function(e) {} # Use withCallingHandlers as that shows the inner stacktrace: # https://stackoverflow.com/questions/15282471/get-stack-trace-on-trycatched-error-in-r # the tryCatch is still needed to prevent the error from showing # up outside further up the stack :-/ data <- filter_map(mimetypes, function(mime) { tryCatch(withCallingHandlers({ if (! mime %in% names(repr::mime2repr)) stop('No repr_* for mimetype ', mime, ' in repr::mime2repr') rpr <- repr::mime2repr[[mime]](obj) if (is.null(rpr)) return(NULL) prepare_content(is.raw(rpr), rpr) }, error = error_handler), error = outer_handler) }) list(data = data, metadata = isolate_full_html(data, metadata)) } prepare_content <- function(isbinary, data = NULL, file = NULL) { if (is.null(file) == is.null(data)) stop('Either need to specify data or file, but not both') if (is.null(file)) { if (isbinary) { if (!is.raw(data)) stop('Data needs to be a raw vector') } data } else { read_all(file, isbinary) } } display_raw <- function(mimetype, isbinary, data, file, metadata = NULL) { content <- prepare_content(isbinary, data, file) data <- list() data[[mimetype]] <- content publish_mimebundle(data, metadata) } IRdisplay/R/utils.r0000644000176200001440000000320213601141377013676 0ustar liggesusers# maps a function and return a named list with the NULL results removed filter_map <- function(x, f, simplify = FALSE) Filter(Negate(is.null), sapply(x, f, simplify = simplify)) # create metadata bundle for images #' @importFrom stats setNames img_metadata <- function(mime, width, height) { if (is.null(width) && is.null(height)) return(NULL) metadata <- list() if (!is.null(width)) metadata$width <- width if (!is.null(height)) metadata$height <- height setNames(list(metadata), mime) } # add an "isolate" flag to -containing data, or the unchanged metadata isolate_full_html <- function(data, metadata = NULL) { if (!('text/html' %in% names(data)) || !isTRUE(grepl('', data[['text/html']], ignore.case = TRUE))) return(metadata) if (is.null(metadata)) metadata <- list() if (is.null(metadata[['text/html']])) metadata[['text/html']] <- list() metadata[['text/html']]$isolated <- TRUE metadata } #' @importFrom methods is read_all <- function(file, isbinary) { read <- if (isbinary) function(s) readBin(file, 'raw', s) else function(s) readChar(file, s) size <- tryCatch(file.info(file)$size, error = function(e) NULL) if (!is.null(size)) { read(size) } else { if (is.character(file)) file <- base::file(file, 'rb') stopifnot(is(file, 'connection')) if (!isOpen(file)) open(file) rv <- if (isbinary) raw() else character() chunk <- read(1024) while (length(chunk) > 0) { rv <- c(rv, chunk) chunk <- read(1024) } rv } } IRdisplay/R/options.r0000644000176200001440000000375414165001607014242 0ustar liggesusers#' IRdisplay options #' #' 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: #' #' \describe{ #' #' \item{\code{jupyter.display_mimetypes}}{ #' The default is all MIME types supported by Jupyter. #' } #' \item{\code{jupyter.base_display_func}}{ #' Function used by \code{\link{display}} and all \code{\link{display_}} / \code{\link{display_}} functions. #' Has the signature \code{function(data, metadata = NULL)}. #' Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. #' } #' \item{\code{jupyter.clear_output_func}}{ #' Function used by \code{\link{clear_output}}. Has the signature \code{function(wait = TRUE)}. #' Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. #' } #' #' } #' #' @name IRdisplay-options #' @export irdisplay_option_defaults <- list( jupyter.display_mimetypes = c( 'text/plain', 'text/html', 'text/markdown', 'text/latex', 'application/json', 'application/javascript', 'application/geo+json', 'application/vdom.v1+json', 'application/vnd.plotly.v1+json', 'application/vnd.vegalite.v2+json', 'application/vnd.vega.v4+json', 'application/pdf', 'image/png', 'image/jpeg', 'image/svg+xml'), jupyter.base_display_func = function(data, metadata = NULL) { warning('IRdisplay can only be used from the IPython R kernel and R magic.') }, jupyter.clear_output_func = function(wait = TRUE) { warning('IRdisplay can only be used from the IPython R kernel and R magic.') }) .onLoad <- function(libname = NULL, pkgname = NULL) { for (option in names(irdisplay_option_defaults)) { if (is.null(getOption(option))) { do.call(options, irdisplay_option_defaults[option]) # single []: preserve name } } } IRdisplay/R/display_textual.r0000644000176200001440000000266114002106336015751 0ustar liggesusers#' Display a specific textual output #' #' Either \code{data} or \code{file} must be passed. #' #' @param data The code or markup content as a \code{\link[base]{character}} vector #' @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_ #' @rdname display-textual NULL #' @rdname display-textual #' @export display_text <- function(data = NULL, file = NULL) display_raw('text/plain', FALSE, data, file) #' @rdname display-textual #' @export display_json <- function(data = NULL, file = NULL) display_raw('application/json', FALSE, data, file) #' @rdname display-textual #' @export display_javascript <- function(data = NULL, file = NULL) display_raw('application/javascript', FALSE, data, file) #' @rdname display-textual #' @export display_html <- function(data = NULL, file = NULL) display_raw('text/html', FALSE, data, file, isolate_full_html(list('text/html' = data))) #' @rdname display-textual #' @export display_markdown <- function(data = NULL, file = NULL) display_raw('text/markdown', FALSE, data, file) #' @rdname display-textual #' @export display_latex <- function(data = NULL, file = NULL) display_raw('text/latex', FALSE, data, file) IRdisplay/R/display_images.r0000644000176200001440000000323113601141377015532 0ustar liggesusers#' Display a specific image output #' #' Either \code{data} or \code{file} must be passed. #' #' @param data The data as a \code{\link[base]{raw}} vector (\code{\link[base]{character}} vector for \code{display_svg}) #' @param file The path to a file or a \code{\link[base]{connection}} containing the content #' @param width The width to display the image #' @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('https://dummyimage.com/600x400.jpg', 'wb'), width = 100)} #' #' @name display_ #' @rdname display-images NULL #' @rdname display-images #' @export display_png <- function(data = NULL, file = NULL, width = NULL, height = NULL) display_img('image/png', TRUE, data, file, width, height) #' @rdname display-images #' @export display_jpeg <- function(data = NULL, file = NULL, width = NULL, height = NULL) display_img('image/jpeg', TRUE, data, file, width, height) #' @rdname display-images #' @export display_pdf <- function(data = NULL, file = NULL, width = NULL, height = NULL) display_img('application/pdf', TRUE, data, file, width, height) #' @rdname display-images #' @export display_svg <- function(data = NULL, file = NULL, width = NULL, height = NULL) display_img('image/svg+xml', FALSE, data, file, width, height) display_img <- function(mime, binary, data, file, width, height) display_raw(mime, binary, data, file, img_metadata(mime, width, height)) IRdisplay/MD50000644000176200001440000000214114165034450012462 0ustar liggesusersed519357e4bf4d5d627829a7434413e7 *DESCRIPTION 3fd4786bf5351f2b5fa63d036ae8e5b2 *LICENSE 102985e772ab2bc721503e49cbb5a2ba *NAMESPACE 5f584763cf30027bf8b357505ee41935 *R/display.r 7a4284abff80b84f59d8d2a0315649b2 *R/display_images.r 02e5e298551695030a97d4081dd5b368 *R/display_textual.r 766d5e880318fdbe6a0539503958b91e *R/options.r f5d8e55356a8eff02597573abee33019 *R/utils.r 93efa7b21032d9378fb672100282509c *README.md 7391679cd5e02965a0e695ce6e29d2b9 *man/IRdisplay-options.Rd 0e2ee4c9d802876a0107b28e43e4135d *man/display-images.Rd 1523bf9b257ea24060cb9a8bf8f2ea0d *man/display-textual.Rd 152a3c928d900d4e9e1e3aadcb46401c *man/display.Rd caad64ea077ced9e1cfd28b5c9db47df *man/publish_mimebundle.Rd 4fd1af4a33f903a0fbaba13bedd228e4 *tests/testthat.R f678acbe698354e19e40e1f53919bd2f *tests/testthat/test-options.r 5364bff55fac94ed7a91ae0811c7efc3 *tests/testthat/test_base_display.r 5e5473056c2bed085d656c147211a059 *tests/testthat/test_display_functions.r 58e4dabeda6f4a40bdc4542ccdf80185 *tests/testthat/test_display_functions_images.r 22fe2c09e5910d045528110fd03d8cd8 *tests/testthat/test_display_functions_textual.r