Skip to content

Commit

Permalink
Added generic reprs for all missing vega* specs
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Dec 16, 2019
1 parent 8172677 commit ddeb9fc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ 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)
Expand All @@ -112,7 +115,10 @@ 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)
Expand Down
29 changes: 28 additions & 1 deletion R/generics.r
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ repr_vegalite2 <- function(obj, ...) UseMethod('repr_vegalite2', obj)
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)
Expand All @@ -159,6 +175,14 @@ repr_vega4 <- function(obj, ...) UseMethod('repr_vega4', obj)
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
Expand All @@ -180,7 +204,10 @@ mime2repr <- list(
'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,
Expand All @@ -189,5 +216,5 @@ mime2repr <- list(
#' @name *2repr
#' @export
format2repr <- sapply(
c('text', 'html', 'markdown', 'latex', 'javascript', 'json', 'geojson', 'vdom1', 'plotly1', 'vegalite2', 'vega4', 'pdf', 'png', 'jpg', 'svg'),
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)))
4 changes: 2 additions & 2 deletions R/repr_vega.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#' @param obj The \link[vegalite]{vegalite} plot to create a representation for
#' @param ... ignored
#'
#' @name repr_vega(4/lite2).*
#' @name repr_vega*
NULL

#' @name repr_vega(4/lite2).*
#' @name repr_vega*
#' @export
repr_vegalite2.vegalite <- function(obj, ...) obj$x
18 changes: 18 additions & 0 deletions man/repr-generics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ddeb9fc

Please sign in to comment.