Permalink
Browse files

Allow empty data frame

  • Loading branch information...
1 parent e644585 commit 5abe0c13134f486544b2bb000b533d45bad9620c @wch wch committed Apr 16, 2012
Showing with 5 additions and 3 deletions.
  1. +2 −1 R/facet-null.r
  2. +1 −1 R/fortify.r
  3. +2 −1 R/panel.r
View
@@ -20,7 +20,8 @@ facet_train_layout.null <- function(facet, data) {
#' @S3method facet_map_layout null
facet_map_layout.null <- function(facet, data, layout) {
- if (empty(data)) return(data.frame(PANEL = 1))
+ if (is.waive(data)) return(data.frame(PANEL = 1))
+ if (nrow(data) == 0) return(cbind(data, PANEL = integer(0)))
data$PANEL <- 1L
data
}
View
@@ -15,7 +15,7 @@
fortify <- function(model, data, ...) UseMethod("fortify")
fortify.data.frame <- function(model, data, ...) model
-fortify.NULL <- function(model, data, ...) data.frame()
+fortify.NULL <- function(model, data, ...) waiver()
fortify.default <- function(model, data, ...) {
stop("ggplot2 doesn't know how to deal with data of class ", class(model), call. = FALSE)
View
@@ -47,7 +47,7 @@ train_layout <- function(panel, facet, data, plot_data) {
# @param plot_data default plot data frame
map_layout <- function(panel, facet, data, plot_data) {
lapply(data, function(data) {
- if (empty(data)) data <- plot_data
+ if (is.waive(data)) data <- plot_data
facet_map_layout(facet, data, panel$layout)
})
}
@@ -138,6 +138,7 @@ map_position <- function(panel, data, x_scale, y_scale) {
# speed
scale_apply <- function(data, vars, f, scale_id, scales) {
if (length(vars) == 0) return()
+ if (nrow(data) == 0) return()
n <- length(scales)
if (any(is.na(scale_id))) stop()

0 comments on commit 5abe0c1

Please sign in to comment.