repr/0000755000176200001440000000000014577247632011243 5ustar liggesusersrepr/NAMESPACE0000644000176200001440000000776514215602251012456 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(repr_geojson,SpatialCollections) S3method(repr_geojson,SpatialGrid) S3method(repr_geojson,SpatialGridDataFrame) S3method(repr_geojson,SpatialLines) S3method(repr_geojson,SpatialLinesDataFrame) S3method(repr_geojson,SpatialPixels) S3method(repr_geojson,SpatialPixelsDataFrame) S3method(repr_geojson,SpatialPoints) S3method(repr_geojson,SpatialPointsDataFrame) S3method(repr_geojson,SpatialPolygons) S3method(repr_geojson,SpatialPolygonsDataFrame) S3method(repr_geojson,SpatialRings) S3method(repr_geojson,SpatialRingsDataFrame) S3method(repr_geojson,default) S3method(repr_geojson,geo_list) S3method(repr_geojson,sf) S3method(repr_geojson,sfc) S3method(repr_geojson,sfg) S3method(repr_html,"function") S3method(repr_html,Date) S3method(repr_html,character) S3method(repr_html,complex) S3method(repr_html,data.frame) S3method(repr_html,data.table) S3method(repr_html,default) S3method(repr_html,factor) S3method(repr_html,help_files_with_topic) S3method(repr_html,htmlwidget) S3method(repr_html,integer) S3method(repr_html,list) S3method(repr_html,logical) S3method(repr_html,matrix) S3method(repr_html,numeric) S3method(repr_html,packageIQR) S3method(repr_html,shiny.tag) S3method(repr_html,shiny.tag.list) S3method(repr_html,ts) S3method(repr_javascript,default) S3method(repr_jpg,default) S3method(repr_jpg,recordedplot) S3method(repr_json,default) S3method(repr_latex,"function") S3method(repr_latex,Date) S3method(repr_latex,character) S3method(repr_latex,complex) S3method(repr_latex,data.frame) S3method(repr_latex,data.table) S3method(repr_latex,default) S3method(repr_latex,factor) S3method(repr_latex,help_files_with_topic) S3method(repr_latex,integer) S3method(repr_latex,list) S3method(repr_latex,logical) S3method(repr_latex,matrix) S3method(repr_latex,numeric) S3method(repr_latex,ts) S3method(repr_markdown,"function") S3method(repr_markdown,Date) S3method(repr_markdown,character) S3method(repr_markdown,complex) S3method(repr_markdown,data.frame) S3method(repr_markdown,default) S3method(repr_markdown,factor) S3method(repr_markdown,integer) S3method(repr_markdown,list) S3method(repr_markdown,logical) S3method(repr_markdown,matrix) S3method(repr_markdown,numeric) S3method(repr_markdown,ts) S3method(repr_pdf,default) S3method(repr_pdf,recordedplot) S3method(repr_plotly1,default) S3method(repr_plotly1,ggplot) S3method(repr_plotly1,plotly) S3method(repr_png,default) S3method(repr_png,recordedplot) S3method(repr_svg,default) S3method(repr_svg,recordedplot) S3method(repr_text,data.frame) S3method(repr_text,data.table) S3method(repr_text,default) S3method(repr_text,help_files_with_topic) S3method(repr_text,htmlwidget) S3method(repr_text,matrix) S3method(repr_text,packageIQR) S3method(repr_text,recordedplot) S3method(repr_text,shiny.tag) S3method(repr_text,shiny.tag.list) S3method(repr_text,ts) S3method(repr_vdom1,default) S3method(repr_vega4,default) S3method(repr_vega5,default) S3method(repr_vegalite2,default) S3method(repr_vegalite2,vegalite) S3method(repr_vegalite3,default) S3method(repr_vegalite4,default) export(format2repr) export(html_dependencies) export(mime2repr) export(repr) export(repr_geojson) export(repr_html) export(repr_javascript) export(repr_jpg) export(repr_json) export(repr_latex) export(repr_markdown) export(repr_option_defaults) export(repr_pdf) export(repr_plotly1) export(repr_png) export(repr_svg) export(repr_text) export(repr_vdom1) export(repr_vega4) export(repr_vega5) export(repr_vegalite2) export(repr_vegalite3) export(repr_vegalite4) importFrom(base64enc,dataURI) importFrom(grDevices,cairo_pdf) importFrom(grDevices,dev.off) importFrom(grDevices,jpeg) importFrom(grDevices,pdf) importFrom(grDevices,png) importFrom(grDevices,replayPlot) importFrom(grDevices,svg) importFrom(htmltools,renderTags) importFrom(jsonlite,fromJSON) importFrom(pillar,type_sum) importFrom(stats,.preformat.ts) importFrom(stats,ts) importFrom(tools,Rd2HTML) importFrom(tools,Rd2latex) importFrom(tools,Rd2txt) importFrom(utils,capture.output) importFrom(utils,head) importFrom(utils,tail) repr/README.md0000644000176200001440000000602114165005264012503 0ustar liggesusersrepr [![b-CI]][CI] [![b-CRAN]][CRAN] ==== [b-CI]: https://github.com/IRkernel/repr/actions/workflows/r.yml/badge.svg "Build status" [CI]: https://github.com/IRkernel/repr/actions/workflows/r.yml [b-CRAN]: https://www.r-pkg.org/badges/version/repr "Comprehensive R Archive Network" [CRAN]: https://cran.r-project.org/package=repr String and byte representations for all kinds of R objects. This package exists to reliably create readable text (and viewable image) representations of data without the side effects [`print()`][print] can cause, such as invoking a [pager][file_show] and plotting to a plot device. In other words, all repr functions and methods are pure. It is intended to be the basis of several packages that need to create rich text and graphics from R objects, such as [Jupyter][]’s [IRkernel][], [knitr][], and others, such as a future more powerful replacement for `R CMD Rd2pdf`. [print]: https://stat.ethz.ch/R-manual/R-devel/library/base/html/print.html [file_show]: https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.show.html [Jupyter]: https://jupyter.org/ [IRkernel]: https://github.com/IRkernel/IRkernel [knitr]: https://yihui.org/knitr/ Exports ------- `repr` is a function delegating to the individual `repr_*` functions. `repr_*`, e.g. `repr_text`, `repr_html`, and `repr_png` emit single-element character vectors or raw vectors. They have parameters also configurable via global `options`. `mime2repr` is a list mapping all known mimetypes to `repr_*` functions, e.g. `mime2repr[['application/pdf']]` is `repr_pdf`. `format2repr` does the same for simple format names. So `format2repr$markdown` is `repr_markdown`. Imports ------- Per default, `repr` will not use any packages not part of the R distribution. Only if you want to use `repr_html.function` and `repr_latex.function`, and specify the parameter `highlight` or option `repr.function.highlight` to be `TRUE`, then be sure to have [highr][] installed. [highr]: https://github.com/yihui/highr Formats ------- Currently, the actually emitted formats are: * Plain text, for everything, using `capture.output(print(thing))`. This will fail if `print(thing)` plots it instead. Please report classes which do that and aren’t handled yet (such as `recordedplot`). * HTML, Markdown, and LaTeX, which are emitted for everything non-graphical * PNG, JPG, SVG, and PDF for everything graphical (ATM just `recordedplot`) Why not Pander? --------------- [Pander][] Is very configurable and does the same as this one, only just for Markdown. Why don’t we use it and use [Pandoc][] to convert to other formats like it? Because it emits just [Markdown][], which is the least semantic format available. A roundtrip through Markdown will undoubtedly create sub-par HTML and LaTeX. Also Pander supports only text. Plots and images are also important to represent. Pander is however awesome for high-quality Markdown so this project might want to depend on it. [Pander]: http://rapporter.github.io/pander/ [Pandoc]: https://pandoc.org/ [Markdown]: https://commonmark.org/ repr/man/0000755000176200001440000000000014577244754012020 5ustar liggesusersrepr/man/repr_-times-.vector.Rd0000644000176200001440000000461513614014563016101 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_vector.r \name{repr_*.vector} \alias{repr_*.vector} \alias{repr_html.logical} \alias{repr_html.integer} \alias{repr_html.complex} \alias{repr_html.numeric} \alias{repr_html.character} \alias{repr_html.Date} \alias{repr_markdown.logical} \alias{repr_markdown.integer} \alias{repr_markdown.complex} \alias{repr_markdown.numeric} \alias{repr_markdown.character} \alias{repr_markdown.Date} \alias{repr_latex.logical} \alias{repr_latex.integer} \alias{repr_latex.complex} \alias{repr_latex.numeric} \alias{repr_latex.character} \alias{repr_latex.Date} \title{Representations of vectors} \usage{ \method{repr_html}{logical}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_html}{integer}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_html}{complex}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_html}{numeric}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_html}{character}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_html}{Date}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{logical}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{integer}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{complex}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{numeric}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{character}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_markdown}{Date}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{logical}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{integer}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{complex}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{numeric}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{character}(obj, ..., items = getOption("repr.vector.max.items")) \method{repr_latex}{Date}(obj, ..., items = getOption("repr.vector.max.items")) } \arguments{ \item{obj}{The vector to create a representation for} \item{...}{ignored} \item{items}{The maximum number of items displayed. The default is given by the option \code{repr.vector.max.items}} } \description{ Representations of vectors } repr/man/repr_-times-.recordedplot.Rd0000644000176200001440000000532213613020677017263 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_recordedplot.r \name{repr_*.recordedplot} \alias{repr_*.recordedplot} \alias{repr_text.recordedplot} \alias{repr_png.recordedplot} \alias{repr_jpg.recordedplot} \alias{repr_svg.recordedplot} \alias{repr_pdf.recordedplot} \title{Plot representations} \usage{ \method{repr_text}{recordedplot}(obj, ...) \method{repr_png}{recordedplot}( obj, width = getOption("repr.plot.width"), height = getOption("repr.plot.height"), bg = getOption("repr.plot.bg"), pointsize = getOption("repr.plot.pointsize"), antialias = getOption("repr.plot.antialias"), res = getOption("repr.plot.res"), ... ) \method{repr_jpg}{recordedplot}( obj, width = getOption("repr.plot.width"), height = getOption("repr.plot.height"), bg = getOption("repr.plot.bg"), pointsize = getOption("repr.plot.pointsize"), antialias = getOption("repr.plot.antialias"), res = getOption("repr.plot.res"), quality = getOption("repr.plot.quality"), ... ) \method{repr_svg}{recordedplot}( obj, width = getOption("repr.plot.width"), height = getOption("repr.plot.height"), bg = getOption("repr.plot.bg"), pointsize = getOption("repr.plot.pointsize"), antialias = getOption("repr.plot.antialias"), family = getOption("repr.plot.family"), ... ) \method{repr_pdf}{recordedplot}( obj, width = getOption("repr.plot.width"), height = getOption("repr.plot.height"), bg = getOption("repr.plot.bg"), pointsize = getOption("repr.plot.pointsize"), antialias = getOption("repr.plot.antialias"), family = getOption("repr.plot.family"), ... ) } \arguments{ \item{obj}{The plot to create a representation for} \item{...}{ignored} \item{width}{Plot area width in inches (default: 7)} \item{height}{Plot area height in inches (default: 7)} \item{bg}{Background color (default: white)} \item{pointsize}{Text height in pt (default: 12)} \item{antialias}{Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray)} \item{res}{For PNG and JPEG, specifies the PPI for rasterization (default: 120)} \item{quality}{For JPEG, determines the compression quality in \% (default: 90)} \item{family}{Font family for SVG and PDF. 'sans', 'serif', 'mono' or a specific one (default: sans)} } \description{ \code{repr_text.recordedplot} only returns a small info string containing the title (if any) while the others return a character vector (SVG) or a raw vector (the rest) containing the image data. } \details{ All parameters can also be specified using the eponymous \code{repr.plot.*} \link{repr-options}. } \examples{ dev.new() dev.control(displaylist = 'enable') plot(sqrt, main = 'Square root') p <- recordPlot() dev.off() repr_text(p) } repr/man/repr_vega-times.Rd0000644000176200001440000000076413613020133015354 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_vega.r \name{repr_vega*} \alias{repr_vega*} \alias{repr_vegalite2.vegalite} \title{Representation as \code{\link[vegalite]{vegalite}v2} or \code{vega4} JSON.} \usage{ \method{repr_vegalite2}{vegalite}(obj, ...) } \arguments{ \item{obj}{The \link[vegalite]{vegalite} plot to create a representation for} \item{...}{ignored} } \description{ Representation as \code{\link[vegalite]{vegalite}v2} or \code{vega4} JSON. } repr/man/repr_-times-.data.table.Rd0000644000176200001440000000105313264370746016600 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_datatable.r \name{repr_*.data.table} \alias{repr_*.data.table} \alias{repr_html.data.table} \alias{repr_text.data.table} \alias{repr_latex.data.table} \title{Representation of data.table objects} \usage{ \method{repr_html}{data.table}(obj, ...) \method{repr_text}{data.table}(obj, ...) \method{repr_latex}{data.table}(obj, ...) } \arguments{ \item{obj}{The list to create a representation for} \item{...}{ignored} } \description{ Representation of data.table objects } repr/man/repr_plotly1.-times.Rd0000644000176200001440000000106013413113543016110 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_plotly.r \name{repr_plotly1.*} \alias{repr_plotly1.*} \alias{repr_plotly1.plotly} \alias{repr_plotly1.ggplot} \title{Representation as \link[plotly:plotly_json]{Plotly JSON}.} \usage{ \method{repr_plotly1}{plotly}(obj, ...) \method{repr_plotly1}{ggplot}(obj, ...) } \arguments{ \item{obj}{The \link[plotly]{plot_ly} plot or \link[ggplot2]{ggplot} to create a representation for} \item{...}{ignored} } \description{ Representation as \link[plotly:plotly_json]{Plotly JSON}. } repr/man/repr_geojson.-times.Rd0000644000176200001440000000364313377231624016173 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_spatial.r \name{repr_geojson.*} \alias{repr_geojson.*} \alias{repr_geojson.geo_list} \alias{repr_geojson.SpatialCollections} \alias{repr_geojson.SpatialPolygons} \alias{repr_geojson.SpatialPolygonsDataFrame} \alias{repr_geojson.SpatialPoints} \alias{repr_geojson.SpatialPointsDataFrame} \alias{repr_geojson.SpatialLines} \alias{repr_geojson.SpatialLinesDataFrame} \alias{repr_geojson.SpatialGrid} \alias{repr_geojson.SpatialGridDataFrame} \alias{repr_geojson.SpatialPixels} \alias{repr_geojson.SpatialPixelsDataFrame} \alias{repr_geojson.SpatialRings} \alias{repr_geojson.SpatialRingsDataFrame} \alias{repr_geojson.sf} \alias{repr_geojson.sfg} \alias{repr_geojson.sfc} \title{Representations of spatial objects: See \link[geojsonio]{geojson_list} for supported classes.} \usage{ \method{repr_geojson}{geo_list}(obj, ...) \method{repr_geojson}{SpatialCollections}(obj, ...) \method{repr_geojson}{SpatialPolygons}(obj, ...) \method{repr_geojson}{SpatialPolygons}(obj, ...) \method{repr_geojson}{SpatialPolygonsDataFrame}(obj, ...) \method{repr_geojson}{SpatialPoints}(obj, ...) \method{repr_geojson}{SpatialPointsDataFrame}(obj, ...) \method{repr_geojson}{SpatialLines}(obj, ...) \method{repr_geojson}{SpatialLinesDataFrame}(obj, ...) \method{repr_geojson}{SpatialGrid}(obj, ...) \method{repr_geojson}{SpatialGridDataFrame}(obj, ...) \method{repr_geojson}{SpatialPixels}(obj, ...) \method{repr_geojson}{SpatialPixelsDataFrame}(obj, ...) \method{repr_geojson}{SpatialRings}(obj, ...) \method{repr_geojson}{SpatialRingsDataFrame}(obj, ...) \method{repr_geojson}{sf}(obj, ...) \method{repr_geojson}{sfg}(obj, ...) \method{repr_geojson}{sfc}(obj, ...) } \arguments{ \item{obj}{The spatial object to create a representation for} \item{...}{ignored} } \description{ Representations of spatial objects: See \link[geojsonio]{geojson_list} for supported classes. } repr/man/times-2repr.Rd0000644000176200001440000000113213704057341014436 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.r \docType{data} \name{*2repr} \alias{*2repr} \alias{mime2repr} \alias{format2repr} \title{Lists mapping mime types (\code{mime2repr}) or format names (\code{format2repr}) to \code{repr} functions} \format{ Lists mapping mime/name to function An object of class \code{list} of length 18. } \usage{ mime2repr format2repr } \description{ Lists mapping mime types (\code{mime2repr}) or format names (\code{format2repr}) to \code{repr} functions } \examples{ names(mime2repr) names(format2repr) } \keyword{datasets} repr/man/repr_-times-.help_files_with_topic.Rd0000644000176200001440000000116713264370746021152 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_help_files_with_topic.r \name{repr_*.help_files_with_topic} \alias{repr_*.help_files_with_topic} \alias{repr_text.help_files_with_topic} \alias{repr_html.help_files_with_topic} \alias{repr_latex.help_files_with_topic} \title{Representations of help} \usage{ \method{repr_text}{help_files_with_topic}(obj, ...) \method{repr_html}{help_files_with_topic}(obj, ...) \method{repr_latex}{help_files_with_topic}(obj, ...) } \arguments{ \item{obj}{Help topic to create a representation for} \item{...}{ignored} } \description{ Representations of help } repr/man/repr_-times-.ts.Rd0000644000176200001440000000147413613020677015227 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_ts.r \name{repr_*.ts} \alias{repr_*.ts} \alias{repr_html.ts} \alias{repr_latex.ts} \alias{repr_markdown.ts} \alias{repr_text.ts} \title{Time series representations} \usage{ \method{repr_html}{ts}(obj, ...) \method{repr_latex}{ts}(obj, ..., colspec = getOption("repr.matrix.latex.colspec")) \method{repr_markdown}{ts}(obj, ...) \method{repr_text}{ts}(obj, ...) } \arguments{ \item{obj}{The \link[stats]{ts} object to create a representation for} \item{...}{ignored} \item{colspec}{The colspec for the LaTeX table. The default is given by the option \code{repr.matrix.latex.colspec}} } \description{ HTML, LaTeX, and Markdown representations of \link[stats]{ts} objects. } \seealso{ \link{repr-options} for \code{repr.matrix.latex.colspec} } repr/man/repr.Rd0000644000176200001440000000140413264362137013242 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.r \name{repr} \alias{repr} \title{Dynamic representation} \usage{ repr(obj, format = "text", ...) } \arguments{ \item{obj}{The object to create a representation for} \item{format}{The representation format. \code{repr_} is then called. (default: Call \link{repr_text})} \item{...}{delegated to the specific \code{repr_} function} } \value{ A character or raw vector of that format or NULL if none is defined. Only the \code{'text'} format is defined for everything (via \link{print}\code{()}) } \description{ Specify an object and a format to represent it in. Will \link{stop}\code{()} if no such format is known. } \seealso{ \link{repr_text}, \link{repr-generics} } repr/man/repr_-times-.htmlwidget.Rd0000644000176200001440000000305013704057341016740 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_htmlwidget.r \docType{data} \name{repr_*.htmlwidget} \alias{repr_*.htmlwidget} \alias{html_dependencies} \alias{repr_text.htmlwidget} \alias{repr_html.htmlwidget} \alias{repr_text.shiny.tag} \alias{repr_*.shiny.tag} \alias{repr_html.shiny.tag} \alias{repr_text.shiny.tag.list} \alias{repr_*.shiny.tag.list} \alias{repr_html.shiny.tag.list} \title{HTML widget representations} \format{ An object of class \code{environment} of length 4. } \usage{ html_dependencies \method{repr_text}{htmlwidget}(obj, ...) \method{repr_html}{htmlwidget}(obj, ...) \method{repr_text}{shiny.tag}(obj, ...) \method{repr_html}{shiny.tag}(obj, ...) \method{repr_text}{shiny.tag.list}(obj, ...) \method{repr_html}{shiny.tag.list}(obj, ...) } \arguments{ \item{obj}{The htmlwidget, shiny.tag, or shiny.tag.list to create a representation for} \item{...}{ignored} } \description{ Standalone HTML representation and dummy text representation. } \details{ \code{html_dependencies} is an \link[base]{environment} containing the following functions. \code{getOption(\link[=repr-options]{'repr.html.deduplicate'})} \describe{ \item{\code{get()}}{Get the list of added dependencies} \item{\code{add(dep)}}{Marks a dependency as added. Call this e.g. after appending a script tag with the dependency.} \item{\code{clear()}}{Clear the list as seen dependencies. Now everything will be added again when encountered.} \item{\code{dir()}}{Returns the directory in which the dependencies reside.} } } \keyword{datasets} repr/man/repr_-times-.function.Rd0000644000176200001440000000142313613020677016420 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_function.r \name{repr_*.function} \alias{repr_*.function} \alias{repr_html.function} \alias{repr_latex.function} \alias{repr_markdown.function} \title{Representations of functions} \usage{ \method{repr_html}{`function`}(obj, highlight = getOption("repr.function.highlight"), ...) \method{repr_latex}{`function`}(obj, highlight = getOption("repr.function.highlight"), ...) \method{repr_markdown}{`function`}(obj, fenced = TRUE, ...) } \arguments{ \item{obj}{Function to create a representation for} \item{highlight}{Should code highlighting be performed} \item{...}{ignored} \item{fenced}{Should a fenced code block instead of an indented one be used?} } \description{ Representations of functions } repr/man/repr-package.Rd0000644000176200001440000000203014577244754014643 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package.r \docType{package} \name{repr-package} \alias{repr-package} \title{The repr package} \description{ String and binary representations of objects for several formats / mime types. } \details{ The LaTeX repr of vectors needs \code{\\usepackage[inline]{enumitem}} The LaTeX repr of functions with the \code{repr.function.highlight} option set to FALSE needs \code{\\usepackage{minted}} } \seealso{ \link{repr}, \link{repr-options}, \link{repr-generics}, \link{repr_text} } \author{ \strong{Maintainer}: Philipp Angerer \email{phil.angerer@gmail.com} (\href{https://orcid.org/0000-0002-0369-2888}{ORCID}) Authors: \itemize{ \item Thomas Kluyver \email{thomas@kluyver.me.uk} \item Jan Schulz \email{jasc@gmx.net} } Other contributors: \itemize{ \item abielr [contributor] \item Denilson Figueiredo de Sa [contributor] \item Jim Hester [contributor] \item karldw [contributor] \item Dave Foster [contributor] \item Carson Sievert [contributor] } } repr/man/repr-options.Rd0000644000176200001440000000535314002103170014717 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/options.r \docType{data} \name{repr-options} \alias{repr-options} \alias{repr_option_defaults} \title{repr options} \format{ An object of class \code{list} of length 15. } \usage{ repr_option_defaults } \description{ These options are used to control the behavior of repr when not calling it directly. Use \code{\link[base]{options}(repr.* = ...)} and \code{\link[base]{getOption}('repr.*')} to set and get them, respectively. } \details{ Once this package is loaded, all options are set to defaults which weren’t set beforehand. Setting all options set to \code{NULL} are reset to defaults when reloading the package (or calling \code{repr:::.onload()}). } \section{Options}{ \describe{ \item{\code{repr.plot.*}}{ Those are for representations of \code{recordedplot} instances: \describe{ \item{\code{repr.plot.width}}{Plotting area width in inches (default: 7)} \item{\code{repr.plot.height}}{Plotting area height in inches (default: 7)} \item{\code{repr.plot.pointsize}}{Text height in pt (default: 12)} \item{\code{repr.plot.bg}}{Background color (default: white)} \item{\code{repr.plot.antialias}}{Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray)} \item{\code{repr.plot.res}}{PPI for rasterization (default: 120)} \item{\code{repr.plot.quality}}{Quality of JPEG format in \% (default: 90)} \item{\code{repr.plot.family}}{Vector font family. 'sans', 'serif', 'mono' or a specific one (default: sans)} } } \item{\code{repr.vector.quote}}{ Output quotation marks for character vectors? (default: TRUE) } \item{\code{repr.vector.max.items}}{ How many items to display at max. Will insert an item with a horizontal ellipsis to show elision. (default: 400) } \item{\code{repr.matrix.max.rows}}{ How many rows to display at max. Will insert a row with vertical ellipses to show elision. (default: 60) } \item{\code{repr.matrix.max.cols}}{ How many cols to display at max. Will insert a column with horizontal ellipses to show elision. (default: 20) } \item{\code{repr.matrix.latex.colspec}}{ How to layout LaTeX tables when representing matrices or data.frames. List of \code{row.head}, other \code{col}, and \code{end} strings. \code{end} mainly exists for when you want a vertical line there (default: 'r|', 'l', and '') } \item{\code{repr.function.highlight}}{ Use the \code{highr} package to insert highlighting instructions into the code? Needs that package to be installed. (default: FALSE) } \item{\code{repr.html.deduplicate}}{ Use the \link{html_dependencies} manager to only include dependencies once? This can greatly reduce notebook size, but fails if e.g. iframes are used (default: FALSE) } } } \keyword{datasets} repr/man/repr-generics.Rd0000644000176200001440000000442313613020133015024 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.r \name{repr-generics} \alias{repr-generics} \alias{repr_html} \alias{repr_html.default} \alias{repr_markdown} \alias{repr_markdown.default} \alias{repr_latex} \alias{repr_latex.default} \alias{repr_json} \alias{repr_json.default} \alias{repr_javascript} \alias{repr_javascript.default} \alias{repr_pdf} \alias{repr_pdf.default} \alias{repr_png} \alias{repr_png.default} \alias{repr_jpg} \alias{repr_jpg.default} \alias{repr_svg} \alias{repr_svg.default} \alias{repr_geojson} \alias{repr_geojson.default} \alias{repr_vdom1} \alias{repr_vdom1.default} \alias{repr_plotly1} \alias{repr_plotly1.default} \alias{repr_vegalite2} \alias{repr_vegalite2.default} \alias{repr_vegalite3} \alias{repr_vegalite3.default} \alias{repr_vegalite4} \alias{repr_vegalite4.default} \alias{repr_vega4} \alias{repr_vega4.default} \alias{repr_vega5} \alias{repr_vega5.default} \title{Representations for specific formats} \usage{ repr_html(obj, ...) \method{repr_html}{default}(obj, ...) repr_markdown(obj, ...) \method{repr_markdown}{default}(obj, ...) repr_latex(obj, ...) \method{repr_latex}{default}(obj, ...) repr_json(obj, ...) \method{repr_json}{default}(obj, ...) repr_javascript(obj, ...) \method{repr_javascript}{default}(obj, ...) repr_pdf(obj, ...) \method{repr_pdf}{default}(obj, ...) repr_png(obj, ...) \method{repr_png}{default}(obj, ...) repr_jpg(obj, ...) \method{repr_jpg}{default}(obj, ...) repr_svg(obj, ...) \method{repr_svg}{default}(obj, ...) repr_geojson(obj, ...) \method{repr_geojson}{default}(obj, ...) repr_vdom1(obj, ...) \method{repr_vdom1}{default}(obj, ...) repr_plotly1(obj, ...) \method{repr_plotly1}{default}(obj, ...) repr_vegalite2(obj, ...) \method{repr_vegalite2}{default}(obj, ...) repr_vegalite3(obj, ...) \method{repr_vegalite3}{default}(obj, ...) repr_vegalite4(obj, ...) \method{repr_vegalite4}{default}(obj, ...) repr_vega4(obj, ...) \method{repr_vega4}{default}(obj, ...) repr_vega5(obj, ...) \method{repr_vega5}{default}(obj, ...) } \arguments{ \item{obj}{The object to create a repr for} \item{...}{parameters of the specific \code{repr_*} functions} } \description{ Representations for specific formats } \seealso{ \link{repr_text} for the only repr that is always defined } repr/man/repr_-times-.factor.Rd0000644000176200001440000000077613413113543016054 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_factor.r \name{repr_*.factor} \alias{repr_*.factor} \alias{repr_html.factor} \alias{repr_markdown.factor} \alias{repr_latex.factor} \title{Representations of factors} \usage{ \method{repr_html}{factor}(obj, ...) \method{repr_markdown}{factor}(obj, ...) \method{repr_latex}{factor}(obj, ...) } \arguments{ \item{obj}{The factor to create a representation for} \item{...}{ignored} } \description{ Representations of factors } repr/man/repr_text.Rd0000644000176200001440000000076613264370746014325 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.r \name{repr_text} \alias{repr_text} \alias{repr_text.default} \title{Text representation} \usage{ repr_text(obj, ...) \method{repr_text}{default}(obj, ...) } \arguments{ \item{obj}{The object to \link{print} and then return the output} \item{...}{ignored} } \description{ The only representation defined per default for everthing (via \link{print}\code{()}) } \seealso{ \link{repr-generics} for other generics } repr/man/repr_-times-.matrix-slash-data.frame.Rd0000644000176200001440000000425613613020677021216 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_matrix_df.r \name{repr_*.matrix/data.frame} \alias{repr_*.matrix/data.frame} \alias{repr_html.matrix} \alias{repr_html.data.frame} \alias{repr_latex.matrix} \alias{repr_latex.data.frame} \alias{repr_markdown.matrix} \alias{repr_markdown.data.frame} \alias{repr_text.matrix} \alias{repr_text.data.frame} \title{Tabular data representations} \usage{ \method{repr_html}{matrix}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) \method{repr_html}{data.frame}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) \method{repr_latex}{matrix}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols"), colspec = getOption("repr.matrix.latex.colspec") ) \method{repr_latex}{data.frame}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols"), colspec = getOption("repr.matrix.latex.colspec") ) \method{repr_markdown}{matrix}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) \method{repr_markdown}{data.frame}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) \method{repr_text}{matrix}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) \method{repr_text}{data.frame}( obj, ..., rows = getOption("repr.matrix.max.rows"), cols = getOption("repr.matrix.max.cols") ) } \arguments{ \item{obj}{The matrix or data.frame to create a representation for} \item{...}{ignored} \item{rows}{The maximum number of rows displayed. The default is given by the option \code{repr.matrix.max.rows}} \item{cols}{The maximum number of columns displayed. The default is given by the option \code{repr.matrix.max.cols}} \item{colspec}{The colspec for the LaTeX table. The default is given by the option \code{repr.matrix.latex.colspec}} } \description{ HTML, LaTeX, and Markdown representations of Matrix-like objects } \seealso{ \link{repr-options} for \code{repr.matrix.latex.colspec} } repr/man/repr_-times-.list.Rd0000644000176200001440000000074613264370746015564 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_list.r \name{repr_*.list} \alias{repr_*.list} \alias{repr_html.list} \alias{repr_markdown.list} \alias{repr_latex.list} \title{Representations of lists} \usage{ \method{repr_html}{list}(obj, ...) \method{repr_markdown}{list}(obj, ...) \method{repr_latex}{list}(obj, ...) } \arguments{ \item{obj}{The list to create a representation for} \item{...}{ignored} } \description{ Representations of lists } repr/man/repr_-times-.packageIQR.Rd0000644000176200001440000000117113465223347016546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/repr_packageIQR.r \name{repr_*.packageIQR} \alias{repr_*.packageIQR} \alias{repr_text.packageIQR} \alias{repr_html.packageIQR} \title{packageIQR representations} \usage{ \method{repr_text}{packageIQR}(obj, ...) \method{repr_html}{packageIQR}(obj, ...) } \arguments{ \item{obj}{The packageIQR obj to create a representation for} \item{...}{ignored} } \description{ Text representations of packageIQR objects like the list of available example data or vignettes } \examples{ repr_html(data(package = 'datasets')) repr_text(vignette(package = 'highr')) } repr/DESCRIPTION0000644000176200001440000000365614577247632012763 0ustar liggesusersPackage: repr Title: Serializable Representations Version: 1.1.7 Authors@R: c( person('Philipp', 'Angerer', email = 'phil.angerer@gmail.com', role = c('aut', 'cre'), comment = c(ORCID = "0000-0002-0369-2888")), person('Thomas', 'Kluyver', email = 'thomas@kluyver.me.uk', role = 'aut'), person('Jan', 'Schulz', email = 'jasc@gmx.net', role = 'aut'), person('abielr', role = 'ctb'), person('Denilson', 'Figueiredo de Sa', role = 'ctb'), person('Jim', 'Hester', role = 'ctb'), person('karldw', role = 'ctb'), person('Dave', 'Foster', role = 'ctb'), person('Carson', 'Sievert', role = 'ctb') ) Maintainer: Philipp Angerer Description: String and binary representations of objects for several formats / mime types. URL: https://github.com/IRkernel/repr/ BugReports: https://github.com/IRkernel/repr/issues/ Depends: R (>= 3.0.1) Imports: utils, grDevices, htmltools, jsonlite, pillar (>= 1.4.0), base64enc Suggests: methods, highr, Cairo, stringr, testthat (>= 3.0.0), leaflet Enhances: data.table, tibble, htmlwidgets, vegalite, plotly, geojsonio Config/testthat/edition: 3 License: GPL (>= 3) Encoding: UTF-8 Collate: 'generics.r' 'options.r' 'package.r' 'repr_datatable.r' 'repr_datetime.r' 'utils.r' 'repr_list.r' 'repr_vector.r' 'repr_factor.r' 'repr_function.r' 'repr_help_files_with_topic.r' 'repr_htmlwidget.r' 'repr_matrix_df.r' 'repr_packageIQR.r' 'repr_plotly.r' 'repr_recordedplot.r' 'repr_spatial.r' 'repr_ts.r' 'repr_vega.r' 'zzz_onload.r' RoxygenNote: 7.3.1 NeedsCompilation: no Packaged: 2024-03-22 09:08:06 UTC; phil Author: Philipp Angerer [aut, cre] (), Thomas Kluyver [aut], Jan Schulz [aut], abielr [ctb], Denilson Figueiredo de Sa [ctb], Jim Hester [ctb], karldw [ctb], Dave Foster [ctb], Carson Sievert [ctb] Repository: CRAN Date/Publication: 2024-03-22 09:30:02 UTC repr/tests/0000755000176200001440000000000013264362137012373 5ustar liggesusersrepr/tests/testthat/0000755000176200001440000000000014577247632014245 5ustar liggesusersrepr/tests/testthat/test_repr_packageIQR.r0000644000176200001440000000176613747300520020460 0ustar liggesusersoptions(stringsAsFactors = FALSE) test_that('repr_html outputs the right html code', { x = vignette() html = repr_html(x) # reprs must return length 1 strings expect_identical(length(html), 1L) expect_type(html, 'character') # test the content no_vignettes_found = '

Vignettes

\n

No vignettes found

\n' expect_true(nchar(html) > nchar(no_vignettes_found)) # there should be at least a few vignettes expect_identical(repr_html(vignette(package = 'repr')), no_vignettes_found) # we don't want to output the LibPath column expect_false(grepl('LibPath', html)) }) test_that('repr_text outputs the right text', { x = vignette() txt = repr_text(x) # reprs must return length 1 strings expect_identical(length(txt), 1L) expect_type(txt, 'character') # test the content no_vignettes_found = 'no vignettes found' expect_true(nchar(txt) > nchar(no_vignettes_found)) # there should be at least a few vignettes expect_identical(repr_text(vignette(package = 'repr')), no_vignettes_found) }) repr/tests/testthat/test_repr_array_df.r0000644000176200001440000001025714577243671020312 0ustar liggesusersoptions(stringsAsFactors = FALSE) test_that('empty data.frames work', { expect_identical(repr_html(data.frame()), '') expect_identical(repr_html(as.data.frame(matrix(integer(0L), 1L, 0L))), '') # no data.frame without colnames possible }) test_that('empty matrices work', { expect_identical(repr_html(matrix(integer(0L), 0L, 0L)), '') expect_identical(repr_html(matrix(integer(0L), 1L, 0L)), '') expect_identical(repr_html(matrix(integer(0L), 0L, 1L)), '') }) test_that('factors display correctly', { df = data.frame(a = factor('iamafactor')) expect_identical(repr_html(df), ' \t \t \t
A data.frame: 1 \u00D7 1
a
<fct>
iamafactor
') }) test_that('mixed factors and strings display correctly', { df = data.frame(a = 'iamastring', b = factor('iamafactor')) expect_true(is.factor(df$b)) expect_identical(repr_html(df), ' \t \t \t
A data.frame: 1 \u00D7 2
ab
<chr><fct>
iamastringiamafactor
') }) test_that('date display correctly', { df = data.frame(a = as.POSIXct('2016-05-28 10:00:00', tz = 'UTC')) expect_identical(repr_html(df), ' \t \t \t
A data.frame: 1 \u00D7 1
a
<dttm>
2016-05-28 10:00:00
') }) test_that('markdown works', { df <- data.frame(a = 1:2, b = letters[1:2]) expect_identical(repr_markdown(df), ' A data.frame: 2 \u00D7 2 | a <int> | b <chr> | |---|---| | 1 | a | | 2 | b | ') }) test_that('markdown works with rownames', { df <- data.frame(a = 1:2, b = letters[1:2], row.names = LETTERS[1:2]) expect_identical(repr_markdown(df), ' A data.frame: 2 \u00D7 2 | | a <int> | b <chr> | |---|---|---| | A | 1 | a | | B | 2 | b | ') }) test_that('latex works', { df <- data.frame(a = 1:2, b = letters[1:2]) expected <- 'A data.frame: 2 \u00D7 2 \\begin{tabular}{ll} a & b\\\\ & \\\\ \\hline \t 1 & a\\\\ \t 2 & b\\\\ \\end{tabular} ' expect_identical(repr_latex(df), expected) }) test_that('latex works with rownames', { df <- data.frame(a = 1:2, b = letters[1:2], row.names = LETTERS[1:2]) expected <- 'A data.frame: 2 \u00D7 2 \\begin{tabular}{r|ll} & a & b\\\\ & & \\\\ \\hline \tA & 1 & a\\\\ \tB & 2 & b\\\\ \\end{tabular} ' expect_identical(repr_latex(df), expected) }) test_that('nested data.frames work', { df <- data.frame(driver = c('Bowser', 'Peach')) df$vehicle <- data.frame(model = c('Piranha Prowler', 'Royal Racer')) df$vehicle$stats <- data.frame(speed = c(55, 34), weight = c(67, 24), drift = c(35, 32)) df$occupation <- c('Koopa', 'Princess') expect_identical(repr_markdown(df), ' A data.frame: 2 \u00D7 6 | driver <chr> | vehicle.model <chr> | vehicle.stats.speed <dbl> | vehicle.stats.weight <dbl> | vehicle.stats.drift <dbl> | occupation <chr> | |---|---|---|---|---|---| | Bowser | Piranha Prowler | 55 | 67 | 35 | Koopa | | Peach | Royal Racer | 34 | 24 | 32 | Princess | ') }) test_that('matrices in data.frames work', { df <- aggregate(. ~ Species, iris, range) expect_equal(dim(df$Sepal.Width), c(3, 2)) expect_identical(repr_markdown(df), ' A data.frame: 3 \u00D7 5 | Species <fct> | Sepal.Length <dbl[,2]> | Sepal.Width <dbl[,2]> | Petal.Length <dbl[,2]> | Petal.Width <dbl[,2]> | |---|---|---|---|---| | setosa | 4.3, 5.8 | 2.3, 4.4 | 1.0, 1.9 | 0.1, 0.6 | | versicolor | 4.9, 7.0 | 2.0, 3.4 | 3.0, 5.1 | 1.0, 1.8 | | virginica | 4.9, 7.9 | 2.2, 3.8 | 4.5, 6.9 | 1.4, 2.5 | ') }) test_that('reprs work on an 1d array', { state <- factor(c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa", "qld", "vic")) incomes <- c(60, 49, 40, 61, 64, 60, 59, 54, 62, 69) one_d_arr <- tapply(incomes, state, mean) repr_html(one_d_arr) repr_latex(one_d_arr) repr_markdown(one_d_arr) succeed() }) repr/tests/testthat/test_utils.r0000644000176200001440000000134514412541630016611 0ustar liggesuserstest_that('Extra arguments to data_uris error', { expect_error( data_uris('one', mime = 'text/html'), 'length(list(...)) == 0L is not TRUE', fixed = TRUE ) }) test_that('data_uris works with one or multiple files', { f1 <- tempfile(fileext = '.js') f2 <- tempfile(fileext = '.js') fh <- file(f1, 'wb') writeBin(charToRaw('one'), fh) close(fh) fh <- file(f2, 'wb') writeBin(charToRaw('two'), fh) close(fh) files <- c(f1, f2) expect_equal( as.character(data_uris(mime = 'text/plain', files = files[[1L]])), 'data:text/plain;base64,b25l' ) expect_equal( as.character(data_uris(mime = 'text/plain', files = files)), paste0('data:text/plain;base64,', c('b25l', 'dHdv')) ) file.remove(f1) file.remove(f2) }) repr/tests/testthat/test_repr_htmlwidget.r0000644000176200001440000000177714577244754020705 0ustar liggesuserstest_that('A basic tag works', { r <- repr_html(htmltools::div()) expect_identical(r, sprintf(repr:::HTML_SKELETON, '', '
')) }) test_that('A basic widget works', { r <- repr_html(str_view('xy', 'y')) expect_match(r, "xy<\\/span>", fixed = TRUE, all = FALSE) }) test_that('Dependencies work', { r <- repr_html(str_view('xy', 'y')) expect_match(r, '', sub('"', '', dep$name), data_uris(mime = 'application/javascript', files = f) )) } if (length(dep$stylesheet) > 0) { f <- file.path(dep$src$file, dep$stylesheet) # TODO: is this *always* the correct mime type? Use base64enc::checkUTF8() to ensure UTF-8 is OK? html <- c(html, sprintf( '', data_uris(mime = 'text/css;charset-utf-8', files = f) )) } paste(html, collapse = '\n') } HTML_SKELETON <- ' %s %s ' # find a new folder name under the working directory new_dir <- function() { dir_candidate <- new_id() while (dir.exists(dir_candidate)) { dir_candidate <- new_id() } dir_candidate } new_id <- function() basename(tempfile('')) # keep track of what dependencies have been included and where they are located dependency_manager <- function() { deps <- NULL dep_dir <- new_dir() as.environment(list( get = function() deps, add = function(dep) deps <<- unique(c(deps, dep)), clear = function() { deps <<- NULL unlink(dep_dir, recursive = TRUE) }, dir = function() dep_dir )) } #' @name repr_*.htmlwidget #' @export html_dependencies <- dependency_manager() # delete the dependency files that have been copied to the jupyter notebook # webserver location (when this object is garbage collected or upon exiting R) reg.finalizer(html_dependencies, function(deps) deps$clear(), onexit = TRUE) #' HTML widget representations #' #' Standalone HTML representation and dummy text representation. #' #' \code{html_dependencies} is an \link[base]{environment} containing the following functions. #' \code{getOption(\link[=repr-options]{'repr.html.deduplicate'})} #' \describe{ #' \item{\code{get()}}{Get the list of added dependencies} #' \item{\code{add(dep)}}{Marks a dependency as added. Call this e.g. after appending a script tag with the dependency.} #' \item{\code{clear()}}{Clear the list as seen dependencies. Now everything will be added again when encountered.} #' \item{\code{dir()}}{Returns the directory in which the dependencies reside.} #' } #' #' @param obj The htmlwidget, shiny.tag, or shiny.tag.list to create a representation for #' @param ... ignored #' #' @name repr_*.htmlwidget #' @export repr_text.htmlwidget <- function(obj, ...) 'HTML widgets cannot be represented in plain text (need html)' #' @name repr_*.htmlwidget #' @export repr_html.htmlwidget <- embed_tags #' @aliases repr_*.shiny.tag #' @name repr_*.htmlwidget #' @export repr_text.shiny.tag <- function(obj, ...) 'Shiny tags cannot be represented in plain text (need html)' #' @name repr_*.htmlwidget #' @export repr_html.shiny.tag <- embed_tags #' @aliases repr_*.shiny.tag.list #' @name repr_*.htmlwidget #' @export repr_text.shiny.tag.list <- function(obj, ...) 'Shiny tags cannot be represented in plain text (need html)' #' @name repr_*.htmlwidget #' @export repr_html.shiny.tag.list <- embed_tags repr/R/repr_recordedplot.r0000644000176200001440000001264214357076012015336 0ustar liggesusersis_cairo_installed <- function() requireNamespace('Cairo', quietly = TRUE) # checking capability of X11 is slow, the short circult logic avoids # this if any other devices are found. check_capability <- function(dev) { devices <- c(dev, 'aqua', 'cairo', 'X11') for (d in devices) { if (capabilities(d)) return(TRUE) } FALSE } plot_title <- function(p, default = NULL) { for (call in rev(p[[1]])) { args <- call[[2]] if (isTRUE(args[[1]]$name == 'C_title') && !is.null(args[[2]])) { return(args[[2]]) } } default } #' Plot representations #' #' \code{repr_text.recordedplot} only returns a small info string containing the title (if any) #' while the others return a character vector (SVG) or a raw vector (the rest) containing the image data. #' #' All parameters can also be specified using the eponymous \code{repr.plot.*} \link{repr-options}. #' #' @param obj The plot to create a representation for #' @param width Plot area width in inches (default: 7) #' @param height Plot area height in inches (default: 7) #' @param bg Background color (default: white) #' @param pointsize Text height in pt (default: 12) #' @param antialias Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray) #' @param res For PNG and JPEG, specifies the PPI for rasterization (default: 120) #' @param quality For JPEG, determines the compression quality in \% (default: 90) #' @param family Font family for SVG and PDF. 'sans', 'serif', 'mono' or a specific one (default: sans) #' @param ... ignored #' #' @examples #' dev.new() #' dev.control(displaylist = 'enable') #' plot(sqrt, main = 'Square root') #' p <- recordPlot() #' dev.off() #' #' repr_text(p) #' #' @name repr_*.recordedplot #' @export repr_text.recordedplot <- function(obj, ...) { title <- plot_title(obj) if (is.null(title)) { 'plot without title' } else { sprintf('Plot with title %s', dQuote(title)) } } #' @importFrom grDevices replayPlot dev.off repr_recordedplot_generic <- function(obj, ext, binary, dev.cb) { tf <- tempfile(fileext = ext) dev.cb(tf) replayPlot(obj) dev.off() if (binary) readBin(tf, raw(), file.info(tf)$size) else readChar(tf, file.info(tf)$size, useBytes = TRUE) } ### BITMAPS ### #' @name repr_*.recordedplot #' @importFrom grDevices png #' @export repr_png.recordedplot <- function(obj, width = getOption('repr.plot.width'), height = getOption('repr.plot.height'), bg = getOption('repr.plot.bg'), pointsize = getOption('repr.plot.pointsize'), antialias = getOption('repr.plot.antialias'), #special res = getOption('repr.plot.res'), ...) { if (!is_cairo_installed() && !check_capability('png')) return(NULL) dev.cb <- function(tf) if (is_cairo_installed()) Cairo::Cairo(width, height, tf, 'png', pointsize, bg, 'transparent', 'in', res) else png(tf, width, height, 'in', pointsize, bg, res, antialias = antialias) repr_recordedplot_generic(obj, '.png', TRUE, dev.cb) } #' @name repr_*.recordedplot #' @importFrom grDevices jpeg #' @export repr_jpg.recordedplot <- function(obj, width = getOption('repr.plot.width'), height = getOption('repr.plot.height'), bg = getOption('repr.plot.bg'), pointsize = getOption('repr.plot.pointsize'), antialias = getOption('repr.plot.antialias'), #special res = getOption('repr.plot.res'), quality = getOption('repr.plot.quality'), ...) { if (!is_cairo_installed() && !check_capability('jpeg')) return(NULL) dev.cb <- function(tf) if (is_cairo_installed()) Cairo::Cairo(width, height, tf, 'jpeg', pointsize, bg, 'transparent', 'in', res, quality = quality) else jpeg(tf, width, height, 'in', pointsize, quality, bg, res, antialias = antialias) repr_recordedplot_generic(obj, '.jpg', TRUE, dev.cb) } ### VECTOR ### #' @name repr_*.recordedplot #' @importFrom grDevices svg #' @export repr_svg.recordedplot <- function(obj, width = getOption('repr.plot.width'), height = getOption('repr.plot.height'), bg = getOption('repr.plot.bg'), pointsize = getOption('repr.plot.pointsize'), antialias = getOption('repr.plot.antialias'), #special family = getOption('repr.plot.family'), ...) { if (!is_cairo_installed() && !capabilities('cairo')) return(NULL) #only cairo can do SVG dev.cb <- function(tf) if (is_cairo_installed()) Cairo::Cairo(width, height, tf, 'svg', pointsize, bg, 'transparent', 'in') else svg(tf, width, height, pointsize, FALSE, family, bg, antialias) repr_recordedplot_generic(obj, '.svg', FALSE, dev.cb) } #' @name repr_*.recordedplot #' @importFrom grDevices cairo_pdf pdf #' @export repr_pdf.recordedplot <- function(obj, width = getOption('repr.plot.width'), height = getOption('repr.plot.height'), bg = getOption('repr.plot.bg'), pointsize = getOption('repr.plot.pointsize'), antialias = getOption('repr.plot.antialias'), #special family = getOption('repr.plot.family'), ...) repr_recordedplot_generic(obj, '.pdf', TRUE, function(tf) { title <- plot_title(obj, 'Untitled plot') if (capabilities('aqua')) # no import since R CMD check would complain grDevices::quartz(title, width, height, pointsize, family, antialias, 'pdf', tf, bg) else if (is_cairo_installed()) Cairo::Cairo(width, height, tf, 'pdf', pointsize, bg, 'transparent', 'in') else if (capabilities('cairo')) cairo_pdf(tf, width, height, pointsize, FALSE, family, bg, antialias) else pdf(tf, width, height, FALSE, family, title, bg = bg, pointsize = pointsize) }) repr/R/repr_vega.r0000644000176200001440000000045313613020133013552 0ustar liggesusers#' Representation as \code{\link[vegalite]{vegalite}v2} or \code{vega4} JSON. #' #' @param obj The \link[vegalite]{vegalite} plot to create a representation for #' @param ... ignored #' #' @name repr_vega* NULL #' @name repr_vega* #' @export repr_vegalite2.vegalite <- function(obj, ...) obj$x repr/R/repr_ts.r0000644000176200001440000000257613726116325013304 0ustar liggesusers#' Time series representations #' #' HTML, LaTeX, and Markdown representations of \link[stats]{ts} objects. #' #' @param obj The \link[stats]{ts} object to create a representation for #' @param ... ignored #' @param colspec The colspec for the LaTeX table. The default is given by the option \code{repr.matrix.latex.colspec} #' #' @seealso \link{repr-options} for \code{repr.matrix.latex.colspec} #' #' @importFrom stats ts .preformat.ts #' @name repr_*.ts NULL repr_ts_generic <- function(obj, repr_func, wrap, ...) { vec <- .preformat.ts(obj) if (is.matrix(vec)) { # set rows and cols so the whole thing is always displayed rows <- max(nrow(vec), 2L) cols <- max(ncol(vec), 2L) repr_func(vec, ..., rows = rows, cols = cols, caption_override = 'Time Series') } else { # Just a vector sprintf(wrap, 'A Time Series', repr_func(vec, ...)) } } #' @name repr_*.ts #' @export repr_html.ts <- function(obj, ...) repr_ts_generic(obj, repr_html, '%s:
%s', ...) #' @name repr_*.ts #' @export repr_latex.ts <- function(obj, ..., colspec = getOption('repr.matrix.latex.colspec')) repr_ts_generic(obj, repr_latex, '%s:\\\\%s', ..., colspec = colspec) #' @name repr_*.ts #' @export repr_markdown.ts <- function(obj, ...) repr_ts_generic(obj, repr_markdown, '%s: \n%s', ...) #' @name repr_*.ts #' @export repr_text.ts <- function(obj, ...) repr_ts_generic(obj, repr_text, '%s:\n%s', ...) repr/R/repr_factor.r0000644000176200001440000000173013413113543014113 0ustar liggesusers#' Representations of factors #' #' @param obj The factor to create a representation for #' @param ... ignored #' #' @name repr_*.factor #' @include repr_vector.r #' @include utils.r NULL repr_factor_generic <- function(template, repr_vec, repr_lvls = repr_vec) function(obj, ...) sprintf(template, repr_vec(obj, ...), repr_lvls(levels(obj))) # repr_text is defined via print #' @name repr_*.factor #' @export repr_html.factor <- repr_factor_generic( # "display: list-item" because of https://github.com/jupyter/notebook/issues/2223 '%s
Levels: %s
', repr_html.character, function(lvls) strindent(repr_html.character(lvls))) #' @name repr_*.factor #' @export repr_markdown.factor <- repr_factor_generic('%s\n**Levels**: %s', repr_markdown.character) #' @name repr_*.factor #' @export repr_latex.factor <- repr_factor_generic('%s\n\\emph{Levels}: %s', repr_latex.character) repr/R/repr_list.r0000644000176200001440000000472013717326122013620 0ustar liggesusers#' Representations of lists #' #' @param obj The list to create a representation for #' @param ... ignored #' #' @name repr_*.list #' @include utils.r NULL repr_list_generic <- function( vec, fmt, enum_item, named_item, only_named_item, enum_wrap, named_wrap = enum_wrap, ..., numeric_item = named_item, item_uses_numbers = FALSE, escape_fun = identity) { nms <- names(vec) if (identical(nms, '')) { nms <- NULL } else if (!is.null(nms)) { nms <- as.character(sapply(nms, as_name_or_na, USE.NAMES = FALSE)) # adds `` around special chars nms <- escape_fun(nms) } # This does escaping, so no need to escape the content again mapped <- lapply(vec, format2repr[[fmt]]) # if any elements cannot be represented, return NULL if (any(vapply(vec, is.null, logical(1)) != vapply(mapped, is.null, logical(1)))) { NULL } else if (length(mapped) == 1 && !is.null(nms)) { sprintf(only_named_item, nms, mapped[[1]]) } else { # print NULL as 'NULL' mapped <- lapply(mapped, function(itm) ifelse(is.null(itm), 'NULL', itm)) entries <- if (!is.null(nms)) { vapply(seq_along(mapped), function(i) { nm <- nms[[i]] if (is.na(nm) || nchar(nm) == 0) { sprintf(numeric_item, i, mapped[[i]]) } else { sprintf(named_item, nms[[i]], mapped[[i]]) } }, character(1)) } else if (item_uses_numbers) { sprintf(enum_item, seq_along(mapped), mapped) } else { sprintf(enum_item, mapped) } wrap <- if (is.null(nms)) enum_wrap else named_wrap sprintf(wrap, paste0(entries, collapse = '')) } } #' @name repr_*.list #' @export repr_html.list <- function(obj, ...) repr_list_generic( obj, 'html', '\t
  • %s
  • \n', '\t
    $%s
    \n\t\t
    %s
    \n', '$%s = %s', '
      \n%s
    \n', '
    \n%s
    \n', numeric_item = '\t
    [[%s]]
    \n\t\t
    %s
    \n', escape_fun = html_escape) #' @name repr_*.list #' @export repr_markdown.list <- function(obj, ...) repr_list_generic( obj, 'markdown', '%s. %s\n', '$%s\n: %s\n', '**$%s** = %s', '%s\n\n', numeric_item = '[[%s]]\n: %s\n', item_uses_numbers = TRUE, escape_fun = html_escape) #' @name repr_*.list #' @export repr_latex.list <- function(obj, ...) repr_list_generic( obj, 'latex', '\\item %s\n', '\\item[\\$%s] %s\n', '\\textbf{\\$%s} = %s', enum_wrap = '\\begin{enumerate}\n%s\\end{enumerate}\n', named_wrap = '\\begin{description}\n%s\\end{description}\n', numeric_item = '\\item[{[[%s]]}] %s\n', escape_fun = latex_escape) repr/R/generics.r0000644000176200001440000001341713613020133013403 0ustar liggesusers#' Dynamic representation #' #' Specify an object and a format to represent it in. Will \link{stop}\code{()} if no such format is known. #' #' @param obj The object to create a representation for #' @param format The representation format. \code{repr_} is then called. (default: Call \link{repr_text}) #' @param ... delegated to the specific \code{repr_} function #' #' @return A character or raw vector of that format or NULL if none is defined. #' Only the \code{'text'} format is defined for everything (via \link{print}\code{()}) #' #' @seealso \link{repr_text}, \link{repr-generics} #' @export repr <- function(obj, format = 'text', ...) { delegate <- format2repr[[format]] if (is.null(delegate)) stop(sprintf('Repr format %s not known', format)) delegate(obj, ...) } #' Text representation #' #' The only representation defined per default for everthing (via \link{print}\code{()}) #' #' @param obj The object to \link{print} and then return the output #' @param ... ignored #' #' @seealso \link{repr-generics} for other generics #' @export repr_text <- function(obj, ...) UseMethod('repr_text', obj) #' @name repr_text #' @importFrom utils capture.output #' @export repr_text.default <- function(obj, ...) { paste(capture.output(print(obj)), collapse = '\n') } #' Representations for specific formats #' #' @param obj The object to create a repr for #' @param ... parameters of the specific \code{repr_*} functions #' #' @seealso \link{repr_text} for the only repr that is always defined #' @name repr-generics NULL #' @name repr-generics #' @export repr_html <- function(obj, ...) UseMethod('repr_html', obj) #' @name repr-generics #' @export repr_html.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_markdown <- function(obj, ...) UseMethod('repr_markdown', obj) #' @name repr-generics #' @export repr_markdown.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_latex <- function(obj, ...) UseMethod('repr_latex', obj) #' @name repr-generics #' @export repr_latex.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_json <- function(obj, ...) UseMethod('repr_json', obj) #' @name repr-generics #' @export repr_json.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_javascript <- function(obj, ...) UseMethod('repr_javascript', obj) #' @name repr-generics #' @export repr_javascript.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_pdf <- function(obj, ...) UseMethod('repr_pdf', obj) #' @name repr-generics #' @export repr_pdf.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_png <- function(obj, ...) UseMethod('repr_png', obj) #' @name repr-generics #' @export repr_png.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_jpg <- function(obj, ...) UseMethod('repr_jpg', obj) #' @name repr-generics #' @export repr_jpg.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_svg <- function(obj, ...) UseMethod('repr_svg', obj) #' @name repr-generics #' @export repr_svg.default <- function(obj, ...) NULL # jupyterlab also handles those less-common mimetypes #' @name repr-generics #' @export repr_geojson <- function(obj, ...) UseMethod('repr_geojson', obj) #' @name repr-generics #' @export repr_geojson.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vdom1 <- function(obj, ...) UseMethod('repr_vdom1', obj) #' @name repr-generics #' @export repr_vdom1.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_plotly1 <- function(obj, ...) UseMethod('repr_plotly1', obj) #' @name repr-generics #' @export repr_plotly1.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vegalite2 <- function(obj, ...) UseMethod('repr_vegalite2', obj) #' @name repr-generics #' @export repr_vegalite2.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vegalite3 <- function(obj, ...) UseMethod('repr_vegalite3', obj) #' @name repr-generics #' @export repr_vegalite3.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vegalite4 <- function(obj, ...) UseMethod('repr_vegalite4', obj) #' @name repr-generics #' @export repr_vegalite4.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vega4 <- function(obj, ...) UseMethod('repr_vega4', obj) #' @name repr-generics #' @export repr_vega4.default <- function(obj, ...) NULL #' @name repr-generics #' @export repr_vega5 <- function(obj, ...) UseMethod('repr_vega5', obj) #' @name repr-generics #' @export repr_vega5.default <- function(obj, ...) NULL #' Lists mapping mime types (\code{mime2repr}) or format names (\code{format2repr}) to \code{repr} functions #' #' @format Lists mapping mime/name to function #' #' @examples #' names(mime2repr) #' names(format2repr) #' #' @name *2repr #' @export mime2repr <- list( 'text/plain' = repr_text, 'text/html' = repr_html, 'text/markdown' = repr_markdown, 'text/latex' = repr_latex, 'application/javascript' = repr_javascript, 'application/json' = repr_json, 'application/geo+json' = repr_geojson, 'application/vdom.v1+json' = repr_vdom1, 'application/vnd.plotly.v1+json' = repr_plotly1, 'application/vnd.vegalite.v2+json' = repr_vegalite2, 'application/vnd.vegalite.v3+json' = repr_vegalite3, 'application/vnd.vegalite.v4+json' = repr_vegalite4, 'application/vnd.vega.v4+json' = repr_vega4, 'application/vnd.vega.v5+json' = repr_vega5, 'application/pdf' = repr_pdf, 'image/png' = repr_png, 'image/jpeg' = repr_jpg, 'image/svg+xml' = repr_svg) #' @name *2repr #' @export format2repr <- sapply( c('text', 'html', 'markdown', 'latex', 'javascript', 'json', 'geojson', 'vdom1', 'plotly1', paste0('vegalite', 2:4), paste0('vega', 4:5), 'pdf', 'png', 'jpg', 'svg'), function(n) get(paste0('repr_', n))) repr/R/repr_matrix_df.r0000644000176200001440000002513014577244754014637 0ustar liggesusers#' Tabular data representations #' #' HTML, LaTeX, and Markdown representations of Matrix-like objects #' #' @param obj The matrix or data.frame to create a representation for #' @param ... ignored #' @param rows The maximum number of rows displayed. The default is given by the option \code{repr.matrix.max.rows} #' @param cols The maximum number of columns displayed. The default is given by the option \code{repr.matrix.max.cols} #' @param colspec The colspec for the LaTeX table. The default is given by the option \code{repr.matrix.latex.colspec} #' #' @seealso \link{repr-options} for \code{repr.matrix.latex.colspec} #' #' @importFrom pillar type_sum #' @name repr_*.matrix/data.frame #' @include utils.r NULL # There is currently a problem on windows which can't display chars in th # text/plain output, which are not available in the current locale. # See https://github.com/IRkernel/repr/issues/28#issuecomment-208574856 #' @importFrom utils capture.output .char_fallback <- function(char, default) { real_len <- nchar(char) r_len <- nchar(capture.output(cat(char))) if (real_len == r_len) char else default } chars <- new.env() onload_chars <- function() { chars$ellip_h <- .char_fallback('\u22EF', '...') chars$ellip_v <- .char_fallback('\u22EE', '...') chars$ellip_d <- .char_fallback('\u22F1', '') chars$times_s <- .char_fallback('\u00D7', 'x') } arr_partition <- function(a, rows, cols) { stopifnot(rows >= 2L, cols >= 2L) # create sequences of indices to bisect rows and columns part_r <- partition(nrow(a), rows) part_c <- partition(ncol(a), cols) # assign a list of parts that can be coerced to strings if (!is.null(part_r) && !is.null(part_c)) { structure(list( ul = a[part_r$start, part_c$start], ll = a[part_r$end, part_c$start], ur = a[part_r$start, part_c$end ], lr = a[part_r$end, part_c$end ]), omit = 'both') } else if (!is.null(part_r)) { structure(list( upper = a[part_r$start, , drop = FALSE], lower = a[part_r$end, , drop = FALSE]), omit = 'rows') } else if (!is.null(part_c)) { structure(list( left = a[, part_c$start, drop = FALSE], right = a[, part_c$end, drop = FALSE]), omit = 'cols') } else { structure(list(full = a), omit = 'none') } } # unpack tibble and coerce to data.frame arr_part_unpack_tbl <- function(tbl) { tbl_col_format <- function(col, prefix = '') { if (is.data.frame(col)) { res <- mapply(tbl_col_format, col, names(col), SIMPLIFY = FALSE, USE.NAMES = FALSE) res <- do.call(cbind.data.frame, res) names(res) <- paste0(prefix, '$', names(res)) return(res) } else { res <- data.frame(col) names(res) <- prefix return(res) } } res <- mapply(tbl_col_format, tbl, names(tbl), SIMPLIFY = FALSE, USE.NAMES = FALSE) do.call(cbind.data.frame, res) } arr_parts_format <- function(parts) structure(lapply(parts, arr_part_format), omit = attr(parts, 'omit')) arr_part_format <- function(part) { if (inherits(part, 'tbl')) { part <- arr_part_unpack_tbl(part) } f_part <- if (is.data.frame(part)) { vapply(part, function(col) { if (is.matrix(col)) apply(apply(col, 2L, format), 1L, paste, collapse = ', ') else format(col) }, character(nrow(part))) } else { # format(part) would work, but e.g. would left-pad *both* rows of matrix(7:10, 2L) instead of one apply(part, 2L, format) } # vapply returns a vector for 1-column dfs dim(f_part) <- dim(part) dimnames(f_part) <- dimnames(part) f_part } #' @importFrom utils head tail arr_parts_combine <- function(parts, rownms, colnms) { omit <- attr(parts, 'omit') mat <- switch(omit, rows = rbind(parts$upper, chars$ellip_v, parts$lower, deparse.level = 0L), cols = cbind(parts$left, chars$ellip_h, parts$right, deparse.level = 0L), none = parts$full, both = rbind( cbind(parts$ul, chars$ellip_h, parts$ur, deparse.level = 0L), c(rep(chars$ellip_v, ncol(parts$ul)), chars$ellip_d, rep(chars$ellip_v, ncol(parts$ur))), cbind(parts$ll, chars$ellip_h, parts$lr, deparse.level = 0L))) # If there were no dimnames before, as is often true for matrices, don't assign them. if (omit %in% c('rows', 'both') && !is.null(rownms)) { # everything except ellip_v is to fix rownames for tbls, which explicitly set them to 1:n when subsetting rownames(mat) <- c(head(rownms, nrow(parts[[1]])), chars$ellip_v, tail(rownms, nrow(parts[[2]]))) } if (omit %in% c('cols', 'both') && !is.null(colnms)) { colnames(mat)[[ncol(parts[[1]]) + 1L]] <- chars$ellip_h } mat } # returns a character array with optionally a section of columns and rows in the middle replaced by ellipses ellip_limit_arr <- function( a, rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols') ) { parts <- arr_partition(a, rows, cols) stopifnot(match('ll', names(parts)) %in% c(NA, 2L)) # lower has to come second if available f_parts <- arr_parts_format(parts) arr_parts_combine(f_parts, rownames(a), colnames(a)) } # HTML -------------------------------------------------------------------- repr_matrix_generic <- function( x, wrap, header_wrap, headline_wrap, corner, head, body_wrap, row_wrap, row_head, cell, escape_fun = identity, ..., rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols'), caption_override = NULL ) { has_rownames <- has_row_names(x) has_colnames <- !is.null(colnames(x)) && ncol(x) > 0 if (!has_rownames && !has_colnames && 0L %in% dim(x)) return('') # Get infos for caption and type headers is_matrix <- !is.list(x) cls <- if (!is.null(caption_override)) caption_override else if (class(x)[[1]] == 'tbl_df') 'tibble' else class(x)[[1]] dims <- dim(x) types <- if (is_matrix) type_sum(as.vector(x)) else { type_vec <- sprintf('<%s>', sapply(x, type_sum)) # A row limit of 3 is the minimal choice, but we only have 1 anyway as.vector(ellip_limit_arr(matrix(type_vec, nrow = 1L), 3L, cols)) } # TODO: ineffective to flatten the whole thing # But when are we encountering huge nested arrays? x <- ellip_limit_arr(flatten(x), rows, cols) header <- '' if (has_colnames) { headers <- escape_fun(colnames(x)) typehds <- escape_fun(types) header_raw <- if (is_matrix || is.null(headline_wrap)) { # if we have a data frame but no wrapper for header lines, # we just concatenate each column name with its type. headers <- sprintf(head, if (is_matrix) headers else paste(headers, typehds)) if (has_rownames) headers <- c(corner, headers) headline <- paste(headers, collapse = '') if (is.null(headline_wrap)) headline else sprintf(headline_wrap, headline) } else { # else we create one line for names and one for types. headers <- sprintf(head, headers) typehds <- sprintf(head, typehds) if (has_rownames) { headers <- c(corner, headers) typehds <- c(corner, typehds) } headline <- sprintf(headline_wrap, paste(headers, collapse = '')) typeline <- sprintf(headline_wrap, paste(typehds, collapse = '')) paste0(headline, typeline) } header <- sprintf(header_wrap, header_raw) stopifnot(length(header) == 1L) } rows <- lapply(seq_len(nrow(x)), function(r) { row <- escape_fun(slice_row(x, r)) cells <- sprintf(cell, row) if (has_rownames) { row_head <- sprintf(row_head, escape_fun(rownames(x)[[r]])) cells <- c(row_head, cells) } sprintf(row_wrap, paste(cells, collapse = '')) }) body <- sprintf(body_wrap, paste(rows, collapse = '')) caption <- sprintf('A %s: %s %s %s', escape_fun(cls), dims[[1]], chars$times_s, dims[[2]]) if (is.null(caption_override) && is_matrix) caption <- sprintf('%s of type %s', caption, escape_fun(types)) sprintf(wrap, caption, header, body) } #' @name repr_*.matrix/data.frame #' @export repr_html.matrix <- function( obj, ..., rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols') ) repr_matrix_generic( obj, '\n\n%s%s
    %s
    \n', '\n%s\n', '\t%s\n', '', '%s', '\n%s\n', '\t%s\n', '%s', '%s', escape_fun = html_escape_vec, rows = rows, cols = cols, ...) #' @name repr_*.matrix/data.frame #' @export repr_html.data.frame <- repr_html.matrix # LaTeX ------------------------------------------------------------------- #' @name repr_*.matrix/data.frame #' @export repr_latex.matrix <- function( obj, ..., rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols'), colspec = getOption('repr.matrix.latex.colspec') ) { cols_spec <- paste0(paste(rep(colspec$col, min(cols + 1L, ncol(obj))), collapse = ''), colspec$end) if (has_row_names(obj)) { row_head <- colspec$row_head if (is.null(row_head)) row_head <- colspec$row.head # backwards compat cols_spec <- paste0(colspec$row_head, cols_spec) } r <- repr_matrix_generic( obj, # todo: captionof or so sprintf('%%s\n\\begin{tabular}{%s}\n%%s%%s\\end{tabular}\n', cols_spec), '%s\\hline\n', '%s\\\\\n', ' &', ' %s &', '%s', '\t%s\\\\\n', '%s &', ' %s &', escape_fun = latex_escape_vec, rows = rows, cols = cols, ...) #TODO: remove this quick’n’dirty post processing gsub(' &\\', '\\', r, fixed = TRUE) } #' @name repr_*.matrix/data.frame #' @export repr_latex.data.frame <- repr_latex.matrix # Markdown ------------------------------------------------------------------- #' @name repr_*.matrix/data.frame #' @export repr_markdown.matrix <- function( obj, ..., rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols') ) { obj <- flatten(obj) out_cols <- min(ncol(obj), cols + 1L) + as.integer(has_row_names(obj)) underline <- paste(rep('---', out_cols), collapse = '|') repr_matrix_generic( obj, '\n%s\n\n%s%s\n', sprintf('|%%s\n|%s|\n', underline), NULL, ' |', ' %s |', '%s', '|%s\n', ' %s |', ' %s |', escape_fun = markdown_escape, rows = rows, cols = cols, ...) } #' @name repr_*.matrix/data.frame #' @export repr_markdown.data.frame <- repr_markdown.matrix # Text ------------------------------------------------------------------- #' @name repr_*.matrix/data.frame #' @importFrom utils capture.output #' @export repr_text.matrix <- function( obj, ..., rows = getOption('repr.matrix.max.rows'), cols = getOption('repr.matrix.max.cols') ) { if (inherits(obj, c('data.table'))) { # Coerce to data.frame to avoid special printing in data.table. obj <- as.data.frame(obj) } limited_obj <- ellip_limit_arr(obj, rows, cols) print_output <- capture.output(print(limited_obj, quote = FALSE)) paste(print_output, collapse = '\n') } #' @name repr_*.matrix/data.frame #' @export repr_text.data.frame <- repr_text.matrix repr/R/repr_help_files_with_topic.r0000644000176200001440000000464614142466411017216 0ustar liggesusers# override utils:::print.help_files_with_topic #' Representations of help #' #' @param obj Help topic to create a representation for #' @param ... ignored #' #' @name repr_*.help_files_with_topic NULL fetch_rd_db <- utils::getFromNamespace('fetchRdDB', 'tools') # copy of utils:::.getHelpFile, necessary because CRAN doesn’t like us using ::: get_help_file <- function(file) { path <- dirname(file) dirpath <- dirname(path) if (!file.exists(dirpath)) stop(sprintf('invalid %s argument', sQuote('file'))) pkgname <- basename(dirpath) rd_db <- file.path(path, pkgname) if (!file.exists(paste(rd_db, 'rdx', sep = '.'))) stop(sprintf('package %s exists but was not installed under R >= 2.10.0 so help cannot be accessed', sQuote(pkgname))) fetch_rd_db(rd_db, basename(file)) } #' @importFrom utils capture.output #' @importFrom tools Rd2HTML repr_help_files_with_topic_generic <- function(obj, Rd2_) { topic <- attr(obj, 'topic') #type <- attr(obj, 'type') #should we make this html by setting some option? #tried_all_packages <- attr(obj, 'tried_all_packages') #TODO: handle tried_all_packages paths <- as.character(obj) if (length(paths) == 0) { return(paste(gettextf('No documentation for %s in specified packages and libraries:', sQuote(topic)), gettextf('you could try %s', sQuote(paste0('??', topic))), sep = '\n')) } #TODO: handle multiple file <- paths[[1]] pkgname <- basename(dirname(dirname(file))) rd <- get_help_file(file) output <- capture.output(Rd2_(rd, package = pkgname, outputEncoding = 'UTF-8')) if (identical(Rd2_, Rd2HTML)) { head.end.idx <- which(startsWith(output, '')) body.end.idx <- which(endsWith(output, '')) rm.idx <- c(seq_len(head.end.idx), body.end.idx) output <- output[-rm.idx] } #TODO: replace all the Rd-specific envs in latex paste(output, collapse = '\n') } #' @name repr_*.help_files_with_topic #' @importFrom tools Rd2txt #' @export repr_text.help_files_with_topic <- function(obj, ...) repr_help_files_with_topic_generic(obj, Rd2txt) #' @name repr_*.help_files_with_topic #' @importFrom tools Rd2HTML #' @export repr_html.help_files_with_topic <- function(obj, ...) repr_help_files_with_topic_generic(obj, Rd2HTML) #TODO: markdown #' @name repr_*.help_files_with_topic #' @importFrom tools Rd2latex #' @export repr_latex.help_files_with_topic <- function(obj, ...) repr_help_files_with_topic_generic(obj, Rd2latex) repr/R/utils.r0000644000176200001440000001243513614014563012756 0ustar liggesusershtml_specials <- list('&' = '&', '<' = '<', '>' = '>') html_escape <- function(text, do_spaces = TRUE) { for (chr in names(html_specials)) { text <- gsub(chr, html_specials[[chr]], text, fixed = TRUE) } if (do_spaces) { consec_spaces <- grepl(' ', text) text[consec_spaces] <- sprintf('%s', text[consec_spaces]) } text } latex_specials <- list( '\\' = '\\textbackslash{}', '{' = '\\{', '}' = '\\}', '$' = '\\$', '^' = '\\textasciicircum{}', '_' = '\\_', '%' = '\\%', '#' = '\\#', '&' = '\\&', '~' = '\\textasciitilde{}', '[' = '{[}', ']' = '{]}', '|' = '\\textbar{}') latex_escape <- function(text) { for (chr in names(latex_specials)) { text <- gsub(chr, latex_specials[[chr]], text, fixed = TRUE) } # undo superfluous escape gsub('\\textbackslash\\{\\}', '\\textbackslash{}', text, fixed = TRUE) } markdown_escape <- function(values) { # TODO also replace Markdown values <- html_escape(values, do_spaces = FALSE) values <- ifelse(grepl('^\\s*$', values), '', values) values } .escape_names <- function(obj, escape_type) { # Generic function for escaping names. # Depending on the object type, names, rownames and colnames may be the same or different # Capture all three before changing them. # Note that the resulting names may not be valid R syntax. # escape_type must be 'latex' or 'html' stopifnot(any(escape_type == c('html', 'latex'))) obj_names <- names(obj) obj_rownames <- rownames(obj) obj_colnames <- if (length(dim(obj_names)) > 1L) colnames(obj) else NULL detect_specials <- match.fun(paste0('any_', escape_type, '_specials')) escape_specials <- match.fun(paste0(escape_type, '_escape')) if (detect_specials(obj_names)) names(obj) <- escape_specials(obj_names) if (detect_specials(obj_rownames)) rownames(obj) <- escape_specials(obj_rownames) if (length(dim(obj_names)) > 1L && detect_specials(obj_colnames)) colnames(obj) <- escape_specials(obj_colnames) obj } .any_specials <- function(char_vec, specials_list) { # Use this function to avoid setting names unnecessarily (and thereby copying the object many times). if (inherits(char_vec, c('character', 'factor'))) any(vapply(names(specials_list), grepl, logical(length(char_vec)), char_vec, fixed = TRUE)) else FALSE } .escape_vec <- function(vec, escape_type = c('html', 'latex')) { escape_type <- match.arg(escape_type) # .escape_vec should never change the class of its input. # That seems useful, since functions like ellip_limit_arr check class. if (!is.vector(vec) && !is.factor(vec)) { stop('expected `vec` to be a vector or factor but it is a ', paste(class(vec), collapse = ', ')) } detect_specials <- match.fun(paste0('any_', escape_type, '_specials')) escape_specials <- match.fun(paste0(escape_type, '_escape')) if (detect_specials(vec)) { if (is.factor(vec)) { levels(vec) <- escape_specials(levels(vec)) } else { vec <- escape_specials(vec) # regular character vec } } vec } slice_row <- function(df, row) { # Slice an array, kind of like unlist(obj[row, ]), but respecting factors and # upcasting as necessary. slice <- c(df[row, ], recursive = TRUE) col_classes <- vapply(df, class, FUN.VALUE = character(1L)) for (col_idx in which(col_classes == 'factor')) { # This syntax doesn't work with matrices, but factor matrices are close to # impossible. See: http://stackoverflow.com/a/28724756 slice[col_idx] <- levels(df[[col_idx]])[df[[row, col_idx]]] } slice } strindent <- function(string, indent = '\t') { stripped <- gsub('\n$', '', string) gsub('\n', paste0('\n', indent), paste0(indent, stripped)) } as_name_or_na <- function(x) { if (is.na(x)) '' else if (is.character(x) && nchar(x) == 0) NA_character_ else as.name(x) } # Create the actually-used functions from the shells above. latex_escape_names <- function(obj) .escape_names(obj, 'latex') html_escape_names <- function(obj) .escape_names(obj, 'html') any_latex_specials <- function(char_vec) .any_specials(char_vec, latex_specials) any_html_specials <- function(char_vec) .any_specials(char_vec, html_specials) latex_escape_vec <- function(vec) .escape_vec(vec, 'latex') html_escape_vec <- function(vec) .escape_vec(vec, 'html') #' @importFrom base64enc dataURI data_uris <- function(..., mime = '', encoding = 'base64', files) { stopifnot(length(list(...)) == 0L) vapply( files, function(f) dataURI(mime = mime, encoding = encoding, file = f), character(1L)) } has_row_names <- function(x) { if (is.data.frame(x)) .row_names_info(x) > 0 else !is.null(rownames(x)) } flatten <- function(x){ if (!is.data.frame(x)) return(x) dfcolumns <- rle(vapply(x, is.data.frame, logical(1L))) if (!any(dfcolumns$values)) return(x) end <- cumsum(dfcolumns$lengths) start <- end - dfcolumns$lengths + 1 parts <- mapply(function(start, end, do_flatten) { if (do_flatten) flatten(x[, start:end]) else x[, start:end] }, start = start, end = end, do_flatten = dfcolumns$values, SIMPLIFY = FALSE) names(parts) <- colnames(x) do.call(cbind, parts) } partition <- function(n_items, max_items) { many_items <- max_items < n_items # create sequences of indices to bisect rows and columns if (many_items) list( start = seq_len(ceiling(max_items / 2)), end = seq.int(n_items - floor(max_items / 2) + 1L, n_items) ) else NULL } repr/R/repr_datetime.r0000644000176200001440000000023113400211726014422 0ustar liggesusers# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time #repr_html.POSIXlt <- #repr_html.POSIXct <- #repr_html.date <- #repr_html.dates <- repr/R/repr_plotly.r0000644000176200001440000000072413413114703014161 0ustar liggesusers#' Representation as \link[plotly:plotly_json]{Plotly JSON}. #' #' @param obj The \link[plotly]{plot_ly} plot or \link[ggplot2]{ggplot} to create a representation for #' @param ... ignored #' #' @name repr_plotly1.* NULL #' @importFrom jsonlite fromJSON #' @name repr_plotly1.* #' @export repr_plotly1.plotly <- function(obj, ...) fromJSON(plotly::plotly_json(obj, jsonedit = FALSE)) #' @name repr_plotly1.* #' @export repr_plotly1.ggplot <- repr_plotly1.plotly repr/R/repr_datatable.r0000644000176200001440000000102613264362137014565 0ustar liggesusers#' Representation of data.table objects #' #' @param obj The list to create a representation for #' @param ... ignored #' #' @name repr_*.data.table #' @export repr_html.data.table <- function(obj, ...) { if (data.table::shouldPrint(obj)) NextMethod() } #' @name repr_*.data.table #' @export repr_text.data.table <- function(obj, ...) { if (data.table::shouldPrint(obj)) NextMethod() } #' @name repr_*.data.table #' @export repr_latex.data.table <- function(obj, ...) { if (data.table::shouldPrint(obj)) NextMethod() } repr/R/repr_function.r0000644000176200001440000000301313413113543014456 0ustar liggesusers#' Representations of functions #' #' @param obj Function to create a representation for #' @param highlight Should code highlighting be performed #' @param fenced Should a fenced code block instead of an indented one be used? #' @param ... ignored #' #' @name repr_*.function #' @include utils.r NULL repr_function_generic <- function(f, fmt, escape, high_wrap, norm_wrap, highlight) { code <- deparse(f) if (highlight) { if (!requireNamespace('highr')) stop(sprintf('Tried to create a %s representation of a function with highlighting, but the `highlight` package is not installed!', fmt)) code <- highr::hilight(code, fmt) wrap <- high_wrap } else { code <- escape(code) wrap <- norm_wrap } sprintf(wrap, paste(code, collapse = '\n')) } #' @name repr_*.function #' @export repr_html.function <- function(obj, highlight = getOption('repr.function.highlight'), ...) { wrap <- '
    %s
    ' repr_function_generic(obj, 'html', html_escape, wrap, wrap, highlight, ...) } #' @name repr_*.function #' @export repr_latex.function <- function(obj, highlight = getOption('repr.function.highlight'), ...) { minted_wrap <- '\\begin{minted}{r}\n%s\n\\end{minted}' repr_function_generic(obj, 'latex', latex_escape, '%s', minted_wrap, highlight, ...) } #' @name repr_*.function #' @export repr_markdown.function <- function(obj, fenced = TRUE, ...) { code <- deparse(obj) if (fenced) { code <- c('```r', code, '```') } else { code <- paste0('\t', code) } paste(code, collapse = '\n') } repr/R/repr_packageIQR.r0000644000176200001440000000305213465223347014616 0ustar liggesusers#' packageIQR representations #' #' Text representations of packageIQR objects like the list of available example data or vignettes #' #' @param obj The packageIQR obj to create a representation for #' @param ... ignored #' #' @examples #' repr_html(data(package = 'datasets')) #' repr_text(vignette(package = 'highr')) #' #' @name repr_*.packageIQR #' @export repr_text.packageIQR <- function(obj, ...) { # this is mostly copied from utils:::print.packageIQR db <- as.data.frame(obj$results, stringsAsFactors = FALSE) idx_by_pkg <- split(seq_len(nrow(db)), db$Package) db_by_pkg <- lapply(idx_by_pkg, function(ind) db[ind, ]) output <- character(0L) for (pkg_name in names(db_by_pkg)) { package <- db_by_pkg[[pkg_name]] output <- c( output, sprintf('%s in package %s:\n', obj$title, sQuote(pkg_name)), formatDL(package$Item, package$Title)) } if (length(db_by_pkg) == 0L) output <- c(output, sprintf('no %s found', tolower(obj$title))) if (!is.null(obj$footer)) output <- c(output, paste0('\n', obj$footer)) # add 2 \n paste(output, collapse = '\n') } #' @name repr_*.packageIQR #' @export repr_html.packageIQR <- function(obj, ...) { db <- as.data.frame(obj$results, stringsAsFactors = FALSE)[c('Package', 'Item', 'Title')] title <- sprintf('

    %s

    ', obj$title) content <- if (nrow(db) == 0L) { sprintf('

    No %s found

    ', tolower(obj$title)) } else { repr_html(db, rows = 1000L) } footer <- sprintf('

    %s

    ', obj$footer) # will be character(0L) if is.null(footer) paste(title, content, footer, sep = '\n') } repr/R/package.r0000644000176200001440000000066614577244754013234 0ustar liggesusers#' The repr package #' #' String and binary representations of objects for several formats / mime types. #' #' The LaTeX repr of vectors needs \code{\\usepackage[inline]{enumitem}} #' #' The LaTeX repr of functions with the \code{repr.function.highlight} option set to FALSE needs \code{\\usepackage{minted}} #' #' @seealso \link{repr}, \link{repr-options}, \link{repr-generics}, \link{repr_text} #' #' @name repr-package "_PACKAGE" repr/R/repr_spatial.r0000644000176200001440000000374513377231624014314 0ustar liggesusers#' Representations of spatial objects: See \link[geojsonio]{geojson_list} for supported classes. #' #' @param obj The spatial object to create a representation for #' @param ... ignored #' #' @name repr_geojson.* NULL #' @name repr_geojson.* #' @export repr_geojson.geo_list <- function(obj, ...) unclass(obj) repr_geojson_via_geo_list <- function(obj, ...) repr_geojson(geojsonio::geojson_list(obj), ...) #' @name repr_geojson.* #' @export repr_geojson.SpatialCollections <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPolygons <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPolygons <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPolygonsDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPoints <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPointsDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialLines <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialLinesDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialGrid <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialGridDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPixels <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialPixelsDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialRings <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.SpatialRingsDataFrame <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.sf <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.sfg <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr_geojson.sfc <- repr_geojson_via_geo_list #' @name repr_geojson.* #' @export repr/R/options.r0000644000176200001440000000674614412541630013316 0ustar liggesusers#' repr options #' #' These options are used to control the behavior of repr when not calling it directly. Use \code{\link[base]{options}(repr.* = ...)} and \code{\link[base]{getOption}('repr.*')} to set and get them, respectively. #' #' Once this package is loaded, all options are set to defaults which weren’t set beforehand. #' #' Setting all options set to \code{NULL} are reset to defaults when reloading the package (or calling \code{repr:::.onload()}). #' #' @section Options: #' #' \describe{ #' #' \item{\code{repr.plot.*}}{ #' Those are for representations of \code{recordedplot} instances: #' \describe{ #' \item{\code{repr.plot.width}}{Plotting area width in inches (default: 7)} #' \item{\code{repr.plot.height}}{Plotting area height in inches (default: 7)} #' \item{\code{repr.plot.pointsize}}{Text height in pt (default: 12)} #' \item{\code{repr.plot.bg}}{Background color (default: white)} #' \item{\code{repr.plot.antialias}}{Which kind of antialiasing to use for for lines and text? 'gray', 'subpixel' or 'none'? (default: gray)} #' \item{\code{repr.plot.res}}{PPI for rasterization (default: 120)} #' \item{\code{repr.plot.quality}}{Quality of JPEG format in \% (default: 90)} #' \item{\code{repr.plot.family}}{Vector font family. 'sans', 'serif', 'mono' or a specific one (default: sans)} #' } #' } #' \item{\code{repr.vector.quote}}{ #' Output quotation marks for character vectors? (default: TRUE) #' } #' \item{\code{repr.vector.max.items}}{ #' How many items to display at max. Will insert an item with a horizontal ellipsis to show elision. (default: 400) #' } #' \item{\code{repr.matrix.max.rows}}{ #' How many rows to display at max. Will insert a row with vertical ellipses to show elision. (default: 60) #' } #' \item{\code{repr.matrix.max.cols}}{ #' How many cols to display at max. Will insert a column with horizontal ellipses to show elision. (default: 20) #' } #' \item{\code{repr.matrix.latex.colspec}}{ #' How to layout LaTeX tables when representing matrices or data.frames. #' List of \code{row.head}, other \code{col}, and \code{end} strings. #' \code{end} mainly exists for when you want a vertical line there (default: 'r|', 'l', and '') #' } #' \item{\code{repr.function.highlight}}{ #' Use the \code{highr} package to insert highlighting instructions into the code? Needs that package to be installed. (default: FALSE) #' } #' \item{\code{repr.html.deduplicate}}{ #' Use the \link{html_dependencies} manager to only include dependencies once? This can greatly reduce notebook size, but fails if e.g. iframes are used (default: FALSE) #' } #' #' } #' #' @name repr-options NULL plot_defaults <- list( repr.plot.width = 7, repr.plot.height = 7, repr.plot.pointsize = 12, repr.plot.bg = 'white', repr.plot.antialias = 'gray', #nice medium-res DPI repr.plot.res = 120, #jpeg quality bumped from default repr.plot.quality = 90, #vector font family repr.plot.family = 'sans') class_defaults <- list( repr.vector.quote = TRUE, repr.vector.max.items = 400L, repr.matrix.max.rows = 60L, repr.matrix.max.cols = 20L, repr.matrix.latex.colspec = list(row_head = 'r|', col = 'l', end = ''), repr.function.highlight = FALSE, repr.html.deduplicate = FALSE) #' @name repr-options #' @export repr_option_defaults <- c(plot_defaults, class_defaults) onload_options <- function() { for (opt_name in names(repr_option_defaults)) { if (is.null(getOption(opt_name))) do.call(options, repr_option_defaults[opt_name]) # single []: name stays } } repr/R/repr_vector.r0000644000176200001440000001223414412541630014142 0ustar liggesusers#' Representations of vectors #' #' @param obj The vector to create a representation for #' @param ... ignored #' @param items The maximum number of items displayed. The default is given by the option \code{repr.vector.max.items} #' #' @name repr_*.vector #' @include repr_list.r #' @include utils.r NULL # repr_text is defined via print repr_vector_generic <- function( vec, enum_item, named_item, only_named_item, enum_wrap, named_wrap = enum_wrap, ..., numeric_item = named_item, individual_wrap = NULL, # will be passed the vector items twice so needs 2 times %s item_uses_numbers = FALSE, escape_fun = identity, items = getOption('repr.vector.max.items') ) { if (length(vec) == 0) return('') nms <- names(vec) if (!is.null(nms)) nms <- escape_fun(nms) qt <- is.character(vec) && getOption('repr.vector.quote') # excape_fun is output format specific, encodeString ensures that non-printables come out as \-escapes parts <- partition(length(vec), items) charify <- function(part) escape_fun(encodeString(as.character(part), quote = if (qt) "'" else '')) # see repr_matrix_df.r for chars$ellip_h char_vec <- if (is.null(parts)) charify(vec) else c(charify(vec[parts$start]), chars$ellip_h, charify(vec[parts$end])) if (!is.null(individual_wrap)) { char_vec <- sprintf(individual_wrap, char_vec, char_vec) } if (length(char_vec) > 1) { entries <- if (!is.null(nms)) vapply(seq_along(char_vec), function(i) { nm <- nms[[i]] if (is.na(nm) || nchar(nm) == 0) { sprintf(numeric_item, i, char_vec[[i]]) } else { sprintf(named_item, nms[[i]], char_vec[[i]]) } }, character(1)) else if (item_uses_numbers) sprintf(enum_item, seq_along(char_vec), char_vec) else sprintf(enum_item, char_vec) wrap <- if (is.null(nms)) enum_wrap else named_wrap sprintf(wrap, paste0(entries, collapse = '')) } else if (is.null(nms)) { char_vec } else { sprintf(only_named_item, nms, char_vec) } } # HTML -------------------------------------------------------------------- list_style <- ' ' def_style <- '' repr_html_wrapper <- function(obj, individual_wrap, items, ...) repr_vector_generic( obj, '
  • %s
  • ', '
    %s
    %s
    ', '%s: %s', paste0(list_style, '
      %s
    \n'), paste0(def_style, '
    %s
    \n'), escape_fun = html_escape, individual_wrap = individual_wrap, items = items ) #' @name repr_*.vector #' @export repr_html.logical <- function(obj, ..., items = getOption('repr.vector.max.items')) repr_html_wrapper(obj, NULL, items, ...) #' @name repr_*.vector #' @export repr_html.integer <- repr_html.logical #' @name repr_*.vector #' @export repr_html.complex <- repr_html.logical #' @name repr_*.vector #' @export repr_html.numeric <- repr_html.logical #' @name repr_*.vector #' @export repr_html.character <- repr_html.logical #' @name repr_*.vector #' @export repr_html.Date <- function(obj, ..., items = getOption('repr.vector.max.items')) repr_html_wrapper(obj, '', items, ...) # Markdown ---------------------------------------------------------------- #' @name repr_*.vector #' @export repr_markdown.logical <- function(obj, ..., items = getOption('repr.vector.max.items')) repr_vector_generic( html_escape_names(obj), '%s. %s\n', '%s\n: %s', '**%s:** %s', '%s\n\n', item_uses_numbers = TRUE, escape_fun = html_escape, items = items ) #' @name repr_*.vector #' @export repr_markdown.integer <- repr_markdown.logical #' @name repr_*.vector #' @export repr_markdown.complex <- repr_markdown.logical #' @name repr_*.vector #' @export repr_markdown.numeric <- repr_markdown.logical #' @name repr_*.vector #' @export repr_markdown.character <- repr_markdown.logical #' @name repr_*.vector #' @export repr_markdown.Date <- repr_markdown.logical # LaTeX ------------------------------------------------------------------- #' @name repr_*.vector #' @export repr_latex.logical <- function(obj, ..., items = getOption('repr.vector.max.items')) repr_vector_generic( latex_escape_names(obj), # escape vector names, regardless of class '\\item %s\n', '\\item[%s] %s\n', '\\textbf{%s:} %s', enum_wrap = '\\begin{enumerate*}\n%s\\end{enumerate*}\n', named_wrap = '\\begin{description*}\n%s\\end{description*}\n', only_named_item = '\\textbf{%s:} %s', escape_fun = latex_escape, items = items ) #' @name repr_*.vector #' @export repr_latex.integer <- repr_latex.logical #' @name repr_*.vector #' @export repr_latex.complex <- repr_latex.logical #' @name repr_*.vector #' @export repr_latex.numeric <- repr_latex.logical #' @name repr_*.vector #' @export repr_latex.character <- repr_latex.logical #' @name repr_*.vector #' @export repr_latex.Date <- repr_latex.logical repr/NEWS.md0000644000176200001440000000013114412541630012313 0ustar liggesusers# repr 0.14 * See the [GitHub releases](https://github.com/IRkernel/repr/releases) page repr/MD50000644000176200001440000000607214577247632011560 0ustar liggesusersb060b767cd491f382fc30344840c3b17 *DESCRIPTION 1481cb3093888cc678fce8a07bb21765 *NAMESPACE e2808ff00eb26d3fd818aced86eae6ed *NEWS.md 3cff5bc1af8048e36f17e91eac61a142 *R/generics.r 4a9276d5327eb09e8db462205548f47b *R/options.r 8b497389e194be751db97a9d510a015f *R/package.r eee61312745fc2896c803a7187128ab2 *R/repr_datatable.r 21265614cf2ae86c06aac3cff0c7d050 *R/repr_datetime.r 8c32905f769506f9442efd1097a79dcf *R/repr_factor.r 3cfebb270e5cf04ee62e77a2facdb438 *R/repr_function.r 7e4a0a739bb74313500907daf883d5c2 *R/repr_help_files_with_topic.r 1d2aeee632e138b73c3a41bd5f90e4d1 *R/repr_htmlwidget.r 8c895986bdfe6e5eabcde84d6fe24273 *R/repr_list.r edfc9c48f577bdea997e8ff3fcc40420 *R/repr_matrix_df.r 0bd11dee772560d9c7df028791679093 *R/repr_packageIQR.r 83456dc47fdff45c0a84b3f8fdd287dd *R/repr_plotly.r 2bfb6278c7aefcd9fb74cee02ac7d33b *R/repr_recordedplot.r 06a86d693086afbcfd5c1e5cc84acbaa *R/repr_spatial.r edf1e996da90f5097680052778769a47 *R/repr_ts.r 0e95f818053bc3e5f5b813f9d00d1bb0 *R/repr_vector.r 36fba18c13bb45f28d2033da9acb18c9 *R/repr_vega.r ff12fdad19d9eb7a482d116b119a99c7 *R/utils.r 5f59a99de9b600e11c738628d2288fa7 *R/zzz_onload.r ee557dd0b751889710ae8a71cd385ceb *README.md 9e3a74fda4182812b3d77861725aac48 *man/repr-generics.Rd 77f85d916408adf1472c5082ef67708b *man/repr-options.Rd 0e17c84089db69024763aca7ef9adbf5 *man/repr-package.Rd d1ec0928f9804ba9a25c36a68366959e *man/repr.Rd c3942a737af64e4a59abf2d15b68e16b *man/repr_-times-.data.table.Rd 1d25f9e0c830d775e1b217dbebbe766c *man/repr_-times-.factor.Rd 9abd9b0eb0fee3228fbca17f552ac0e6 *man/repr_-times-.function.Rd ecdd2365b4859736ee6b57e0dfe015d6 *man/repr_-times-.help_files_with_topic.Rd d8f396b9ef340030d0e034717359e0c9 *man/repr_-times-.htmlwidget.Rd b111a6240bcc24dbff9ba61a90a4dcd6 *man/repr_-times-.list.Rd 392a7bad6976e2742ba82d347ed7ee10 *man/repr_-times-.matrix-slash-data.frame.Rd 894094c8b28eb88f1397416cad30a8dd *man/repr_-times-.packageIQR.Rd f73023415bddf9a334703d664eebcb40 *man/repr_-times-.recordedplot.Rd 13d0933bcace5bd91036bf45a99b9f68 *man/repr_-times-.ts.Rd 38bed92e916e3a8cc9df648ac36b75eb *man/repr_-times-.vector.Rd c5b75ad95c25e7d59495a36603b60eab *man/repr_geojson.-times.Rd affc6ac12ac4e660cf45fab20f2bb594 *man/repr_plotly1.-times.Rd 85ab806b85d1462801814ba3f34e904d *man/repr_text.Rd e52d275a12ad0425bc2120e8e16db6dc *man/repr_vega-times.Rd eea24d8d9b81c9fc3c7cfe82ec52d581 *man/times-2repr.Rd 286f184c95373dbc4e2d2539f77aa555 *tests/testthat.R 976c67ea67dda42435540e1bfc9064c8 *tests/testthat/helper-stringr.R 83791319257971863671cbad88c31427 *tests/testthat/test_array_manipulation.r 2408eb0088aab2037868c0a9cb1d796b *tests/testthat/test_escaping.r 9f44fa49d5e263e9b9ec93c01f02fe4a *tests/testthat/test_repr_array_df.r fdcc8ab890a6b702e584f0b7254dd2c3 *tests/testthat/test_repr_htmlwidget.r d5ee85bfbd0b2c741f0ab6d97b4cbedd *tests/testthat/test_repr_list.r 0361c948d62cac86a7a0bd74b0f9546e *tests/testthat/test_repr_packageIQR.r d1e9c5ffc7652a1296a7025d4fdd9b61 *tests/testthat/test_repr_ts.r 54187a1171f399242e57691db55e712f *tests/testthat/test_repr_vector.r 418fba3c112d8b1ca951d904c553b6b4 *tests/testthat/test_utils.r