Skip to content
This repository
Browse code

Allow empty data frame

  • Loading branch information...
commit 5abe0c13134f486544b2bb000b533d45bad9620c 1 parent e644585
Winston Chang wch authored

Showing 3 changed files with 5 additions and 3 deletions. Show diff stats Hide diff stats

  1. +2 1  R/facet-null.r
  2. +1 1  R/fortify.r
  3. +2 1  R/panel.r
3  R/facet-null.r
@@ -20,7 +20,8 @@ facet_train_layout.null <- function(facet, data) {
20 20
21 21 #' @S3method facet_map_layout null
22 22 facet_map_layout.null <- function(facet, data, layout) {
23   - if (empty(data)) return(data.frame(PANEL = 1))
  23 + if (is.waive(data)) return(data.frame(PANEL = 1))
  24 + if (nrow(data) == 0) return(cbind(data, PANEL = integer(0)))
24 25 data$PANEL <- 1L
25 26 data
26 27 }
2  R/fortify.r
@@ -15,7 +15,7 @@
15 15 fortify <- function(model, data, ...) UseMethod("fortify")
16 16
17 17 fortify.data.frame <- function(model, data, ...) model
18   -fortify.NULL <- function(model, data, ...) data.frame()
  18 +fortify.NULL <- function(model, data, ...) waiver()
19 19 fortify.default <- function(model, data, ...) {
20 20
21 21 stop("ggplot2 doesn't know how to deal with data of class ", class(model), call. = FALSE)
3  R/panel.r
@@ -47,7 +47,7 @@ train_layout <- function(panel, facet, data, plot_data) {
47 47 # @param plot_data default plot data frame
48 48 map_layout <- function(panel, facet, data, plot_data) {
49 49 lapply(data, function(data) {
50   - if (empty(data)) data <- plot_data
  50 + if (is.waive(data)) data <- plot_data
51 51 facet_map_layout(facet, data, panel$layout)
52 52 })
53 53 }
@@ -138,6 +138,7 @@ map_position <- function(panel, data, x_scale, y_scale) {
138 138 # speed
139 139 scale_apply <- function(data, vars, f, scale_id, scales) {
140 140 if (length(vars) == 0) return()
  141 + if (nrow(data) == 0) return()
141 142
142 143 n <- length(scales)
143 144 if (any(is.na(scale_id))) stop()

0 comments on commit 5abe0c1

Please sign in to comment.
Something went wrong with that request. Please try again.