Skip to content

Commit

Permalink
Import plyr into namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 13, 2010
1 parent 54c0839 commit e79c075
Show file tree
Hide file tree
Showing 44 changed files with 118 additions and 117 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Minor improvements

Bug fixes

* be explicit about plyr::is.discrete to avoid clash with Hmisc
* be explicit about is.discrete to avoid clash with Hmisc
* facet_wrap: work around R bug so no longer crashers when ncol = 1
* geom_errorbar now works correctly with dashed lines
* geom_path will now silently ignore lines with less than 2 points (instead of throwing a mysterious error as before)
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exportPattern("^[^\\.]")
exportPattern("^[^\\.]")
import(plyr)
2 changes: 1 addition & 1 deletion R/aaa-.r
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ TopLevel <- proto(expr = {
"<p>Parameters control the appearance of the ", .$class(), ". In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.</p>\n",
if(length(param) > 0) ps(
"<ul>\n",
ps("<li><code>", names(param), "</code>: ", plyr::defaults(.$desc_params, .desc_param)[names(param)], "</li>\n"),
ps("<li><code>", names(param), "</code>: ", defaults(.$desc_params, .desc_param)[names(param)], "</li>\n"),
"</ul>\n"
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/aaa-examples.r
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TopLevel$all_examples_run <- function(., path=NULL, verbose=TRUE) {
suppressMessages(x$examples_run(path, verbose))
})

invisible(do.call("rbind", plyr::compact(out)))
invisible(do.call("rbind", compact(out)))
}

# Run all examples
Expand Down
4 changes: 2 additions & 2 deletions R/aaa-rdoc.r
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ TopLevel$rdoc_aesthetics <- function(.) {
if (length(aes) == 0) return("")

req <- ifelse(aes %in% .$required_aes, " (\\strong{required})", "")
desc <- paste(plyr::defaults(.$desc_params, .desc_aes)[aes], req, sep="")
desc <- paste(defaults(.$desc_params, .desc_aes)[aes], req, sep="")

ps(
"\\section{Aesthetics}{\n",
Expand Down Expand Up @@ -158,7 +158,7 @@ TopLevel$rdoc_arguments <- function(.) {

ps(
"\\arguments{\n",
ps(" \\item{", p, "}{", plyr::defaults(.$desc_params, .desc_param)[p], "}\n"),
ps(" \\item{", p, "}{", defaults(.$desc_params, .desc_param)[p], "}\n"),
"}\n"
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/aes.r
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ as.character.uneval <- function(x, ...) {
aesdefaults <- function(data, y., params.) {
updated <- updatelist(y., params.)

cols <- tryapply(plyr::defaults(data, updated), function(x) eval(x, data, globalenv()))
cols <- tryapply(defaults(data, updated), function(x) eval(x, data, globalenv()))

# Need to be careful here because stat_boxplot uses a list-column to store
# a vector of outliers
Expand Down
2 changes: 1 addition & 1 deletion R/annotation.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#X annotate("text", x = 0, y = 0, label = "title")
annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, ...) {

layer_data <- plyr::compact(list(
layer_data <- compact(list(
x = x, xmin = xmin, xmax = xmax,
y = y, ymin = ymin, ymax = ymax
))
Expand Down
24 changes: 12 additions & 12 deletions R/facet-grid-.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FacetGrid <- proto(Facet, {
# Initialisation
initialise <- function(., data) {
.$facet_levels <- unique(
plyr::ldply(data, plyr::failwith(NULL, "[", quiet = TRUE), .$conditionals()))
ldply(data, failwith(NULL, "[", quiet = TRUE), .$conditionals()))

.$shape <- stamp(.$facet_levels, .$facets, margins = .$margins,
function(x) 0)
Expand Down Expand Up @@ -81,7 +81,7 @@ FacetGrid <- proto(Facet, {
for(i in seq_along(.$scales$x)) {
axes_h[[i]] <- coord$guide_axis_h(coord_details[[1, i]], theme)
}
axes_h_height <- do.call("max2", plyr::llply(axes_h, grobHeight))
axes_h_height <- do.call("max2", llply(axes_h, grobHeight))
axeshGrid <- grobGrid(
"axis_h", axes_h, nrow = 1, ncol = nc,
heights = axes_h_height, clip = "off"
Expand All @@ -93,7 +93,7 @@ FacetGrid <- proto(Facet, {
for(i in seq_along(.$scales$y)) {
axes_v[[i]] <- coord$guide_axis_v(coord_details[[i, 1]], theme)
}
axes_v_width <- do.call("max2", plyr::llply(axes_v, grobWidth))
axes_v_width <- do.call("max2", llply(axes_v, grobWidth))
axesvGrid <- grobGrid(
"axis_v", axes_v, nrow = nr, ncol = 1,
widths = axes_v_width, as.table = .$as.table, clip = "off"
Expand All @@ -102,16 +102,16 @@ FacetGrid <- proto(Facet, {
# Strips
labels <- .$labels_default(.$shape, theme)

strip_widths <- plyr::llply(labels$v, grobWidth)
strip_widths <- do.call("unit.c", plyr::llply(1:ncol(strip_widths),
strip_widths <- llply(labels$v, grobWidth)
strip_widths <- do.call("unit.c", llply(1:ncol(strip_widths),
function(i) do.call("max2", strip_widths[, i])))
stripvGrid <- grobGrid(
"strip_v", labels$v, nrow = nrow(labels$v), ncol = ncol(labels$v),
widths = strip_widths, as.table = .$as.table
)

strip_heights <- plyr::llply(labels$h, grobHeight)
strip_heights <- do.call("unit.c", plyr::llply(1:nrow(strip_heights),
strip_heights <- llply(labels$h, grobHeight)
strip_heights <- do.call("unit.c", llply(1:nrow(strip_heights),
function(i) do.call("max2", strip_heights[i, ])))
striphGrid <- grobGrid(
"strip_h", labels$h, nrow = nrow(labels$h), ncol = ncol(labels$h),
Expand All @@ -131,8 +131,8 @@ FacetGrid <- proto(Facet, {

if(.$space_is_free) {
size <- function(y) unit(diff(y$output_expand()), "null")
panel_widths <- do.call("unit.c", plyr::llply(.$scales$x, size))
panel_heights <- do.call("unit.c", plyr::llply(.$scales$y, size))
panel_widths <- do.call("unit.c", llply(.$scales$x, size))
panel_heights <- do.call("unit.c", llply(.$scales$y, size))
} else {
panel_widths <- unit(1, "null")
panel_heights <- unit(1 * aspect_ratio, "null")
Expand All @@ -158,7 +158,7 @@ FacetGrid <- proto(Facet, {
# theme$panel.margin, theme$panel.margin

# from left to right
hgap_widths <- do.call("unit.c", plyr::compact(list(
hgap_widths <- do.call("unit.c", compact(list(
unit(0, "cm"), # no gap after axis
rep.unit2(theme$panel.margin, nc - 1), # gap after all panels except last
unit(rep(0, ncol(stripvGrid) + 1), "cm") # no gap after strips
Expand All @@ -169,7 +169,7 @@ FacetGrid <- proto(Facet, {
)

# from top to bottom
vgap_heights <- do.call("unit.c", plyr::compact(list(
vgap_heights <- do.call("unit.c", compact(list(
unit(rep(0, nrow(striphGrid) + 1), "cm"), # no gap after strips
rep.unit2(theme$panel.margin, nr - 1), # gap after all panels except last
unit(0, "cm") # no gap after axis
Expand Down Expand Up @@ -398,7 +398,7 @@ FacetGrid <- proto(Facet, {
# @keyword internal
scales_list <- function(scale, n, free) {
if (free) {
plyr::rlply(n, scale$clone())
rlply(n, scale$clone())
} else {
rep(list(scale), n)
}
Expand Down
2 changes: 1 addition & 1 deletion R/facet-labels.r
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ label_both <- function(variable, value) paste(variable, value, sep = ": ")
#X qplot(wt, mpg, data = mtcars) + facet_grid(. ~ cyl2,
#X labeller = label_parsed)
label_parsed <- function(variable, value) {
plyr::llply(as.character(value), function(x) parse(text = x))
llply(as.character(value), function(x) parse(text = x))
}

# Label facet with 'bquoted' expressions
Expand Down
2 changes: 1 addition & 1 deletion R/facet-viewports.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ assign_viewports <- function(grobs) {
ggname(type, editGrob(grobs[[type]][[x, y]], vp = vp_path(x, y, type)))
}

grid <- plyr::ldply(names(grobs), make_grid)
grid <- ldply(names(grobs), make_grid)
mlply(grid, assign_vp)
}

Expand Down
18 changes: 9 additions & 9 deletions R/facet-wrap.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FacetWrap <- proto(Facet, {
)

.$proto(
facets = plyr::as.quoted(facets), free = free,
facets = as.quoted(facets), free = free,
scales = NULL, as.table = as.table, drop = drop,
ncol = ncol, nrow = nrow
)
Expand All @@ -20,7 +20,7 @@ FacetWrap <- proto(Facet, {
# Data shape
initialise <- function(., data) {
# Compute facetting variables for all layers
vars <- plyr::ldply(data, function(df) {
vars <- ldply(data, function(df) {
as.data.frame(eval.quoted(.$facets, df))
})

Expand All @@ -36,7 +36,7 @@ FacetWrap <- proto(Facet, {
df <- merge(add_group(df), .$facet_levels, by = .$conditionals())
df <- df[order(df$PANEL, df$.ORDER), ]

out <- as.list(plyr::dlply(df, .(PANEL), .drop = FALSE))
out <- as.list(dlply(df, .(PANEL), .drop = FALSE))
dim(out) <- c(1, nrow(.$facet_levels))
out
})
Expand Down Expand Up @@ -108,15 +108,15 @@ FacetWrap <- proto(Facet, {
)

strips <- .$labels_default(.$facet_levels, theme)
strips_height <- max(do.call("unit.c", plyr::llply(strips, grobHeight)))
strips_height <- max(do.call("unit.c", llply(strips, grobHeight)))
stripsGrid <- grobGrid(
"strip", strips, nrow = nrow, ncol = ncol,
heights = convertHeight(strips_height, "cm"),
widths = 1,
as.table = .$as.table
)

axis_widths <- max(do.call("unit.c", plyr::llply(axes_v, grobWidth)))
axis_widths <- max(do.call("unit.c", llply(axes_v, grobWidth)))
axis_widths <- convertWidth(axis_widths, "cm")
if (.$free$y) {
axesvGrid <- grobGrid(
Expand All @@ -138,7 +138,7 @@ FacetWrap <- proto(Facet, {
}
}

axis_heights <- max(do.call("unit.c", plyr::llply(axes_h, grobHeight)))
axis_heights <- max(do.call("unit.c", llply(axes_h, grobHeight)))
axis_heights <- convertHeight(axis_heights, "cm")
if (.$free$x) {
axeshGrid <- grobGrid(
Expand Down Expand Up @@ -177,11 +177,11 @@ FacetWrap <- proto(Facet, {
labels_default <- function(., labels_df, theme) {
# Remove column giving panel number
labels_df <- labels_df[, -ncol(labels_df), drop = FALSE]
labels_df[] <- plyr::llply(labels_df, format, justify = "none")
labels_df[] <- llply(labels_df, format, justify = "none")

labels <- apply(labels_df, 1, paste, collapse=", ")

plyr::llply(labels, ggstrip, theme = theme)
llply(labels, ggstrip, theme = theme)
}

# Position scales ----------------------------------------------------------
Expand Down Expand Up @@ -266,7 +266,7 @@ FacetWrap <- proto(Facet, {

desc_params <- list(
nrow = "number of rows",
ncol = "number of colums",
ncol = "number of columns",
facet = "formula specifying variables to facet by",
scales = "should scales be fixed, free, or free in one dimension (\\code{free_x}, \\code{free_y}) "
)
Expand Down
2 changes: 1 addition & 1 deletion R/fortify-map.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fortify.map <- function(model, data, ...) {
#X if (require(maps)) {
#X ia <- map_data("county", "iowa")
#X mid_range <- function(x) mean(range(x))
#X seats <- ddply(ia, .(subregion), plyr::colwise(mid_range, .(lat, long)))
#X seats <- ddply(ia, .(subregion), colwise(mid_range, .(lat, long)))
#X ggplot(ia, aes(long, lat)) +
#X geom_polygon(aes(group = group), fill = NA, colour = "grey60") +
#X geom_text(aes(label = subregion), data = seats, size = 2, angle = 45)
Expand Down
8 changes: 4 additions & 4 deletions R/fortify-spatial.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ fortify.SpatialPolygonsDataFrame <- function(model, data, region = NULL, ...) {
}

fortify.SpatialPolygons <- function(model, data, ...) {
plyr::ldply(model@polygons, fortify)
ldply(model@polygons, fortify)
}

fortify.Polygons <- function(model, data, ...) {
subpolys <- model@Polygons
pieces <- plyr::ldply(seq_along(subpolys), function(i) {
pieces <- ldply(seq_along(subpolys), function(i) {
df <- fortify(subpolys[[model@plotOrder[i]]])
df$piece <- i
df
Expand All @@ -65,12 +65,12 @@ fortify.Polygon <- function(model, data, ...) {
}

fortify.SpatialLinesDataFrame <- function(model, data, ...) {
plyr::ldply(model@lines, fortify)
ldply(model@lines, fortify)
}

fortify.Lines <- function(model, data, ...) {
lines <- model@Lines
pieces <- plyr::ldply(seq_along(lines), function(i) {
pieces <- ldply(seq_along(lines), function(i) {
df <- fortify(lines[[i]])
df$piece <- i
df
Expand Down
2 changes: 1 addition & 1 deletion R/geom-abline.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GeomAbline <- proto(Geom, {
new <- function(., mapping = NULL, ...) {
mapping <- plyr::compact(plyr::defaults(mapping, aes(group = 1)))
mapping <- compact(defaults(mapping, aes(group = 1)))
class(mapping) <- "uneval"
.super$new(., ..., mapping = mapping, inherit.aes = FALSE)
}
Expand Down
4 changes: 2 additions & 2 deletions R/geom-defaults.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ update_geom_defaults <- function(geom, new) {
g <- Geom$find(geom)
old <- g$default_aes()

aes <- plyr::defaults(new, old)
aes <- defaults(new, old)

g$default_aes <- eval(substitute(function(.) aes, list(aes = aes)))
}
Expand All @@ -31,6 +31,6 @@ update_stat_defaults <- function(geom, new) {
g <- Stat$find(geom)
old <- g$default_aes()

aes <- plyr::defaults(new, old)
aes <- defaults(new, old)
g$default_aes <- eval(substitute(function(.) aes, list(aes = aes)))
}
2 changes: 1 addition & 1 deletion R/geom-path-.r
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ GeomPath <- proto(Geom, {

examples <- function(.) {
# Generate data
myear <- ddply(movies, .(year), plyr::colwise(mean, .(length, rating)))
myear <- ddply(movies, .(year), colwise(mean, .(length, rating)))
p <- ggplot(myear, aes(length, rating))
p + geom_path()

Expand Down
2 changes: 1 addition & 1 deletion R/geom-quantile.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GeomQuantile <- proto(GeomPath, {

advice <- "<p>This can be used as a continuous analogue of a geom_boxplot.</p>\n"
default_stat <- function(.) StatQuantile
default_aes <- function(.) plyr::defaults(aes(weight=1, colour="#3366FF", size=0.5), GeomPath$default_aes())
default_aes <- function(.) defaults(aes(weight=1, colour="#3366FF", size=0.5), GeomPath$default_aes())
guide_geom <- function(.) "path"


Expand Down
2 changes: 1 addition & 1 deletion R/geom-rect.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GeomRect <- proto(Geom, {
names(data), c("x", "y", "xmin","xmax", "ymin", "ymax")
)

polys <- plyr::alply(data, 1, function(row) {
polys <- alply(data, 1, function(row) {
poly <- with(row, rect_to_poly(xmin, xmax, ymin, ymax))
aes <- as.data.frame(row[aesthetics],
stringsAsFactors = FALSE)[rep(1,5), ]
Expand Down
2 changes: 1 addition & 1 deletion R/geom-ribbon-density.r
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GeomDensity <- proto(GeomArea, {
geom_histogram = "for the histogram"
)

default_aes <- function(.) plyr::defaults(aes(fill=NA, weight=1, colour="black", alpha = 1), GeomArea$default_aes())
default_aes <- function(.) defaults(aes(fill=NA, weight=1, colour="black", alpha = 1), GeomArea$default_aes())

examples <- function(.) {
# See stat_density for examples
Expand Down
Loading

0 comments on commit e79c075

Please sign in to comment.