Skip to content

Commit

Permalink
Supply all arguments to match.arg
Browse files Browse the repository at this point in the history
Do not rely on argument evaluation
  • Loading branch information
jiho authored and wch committed Aug 17, 2012
1 parent bcd9961 commit a658737
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/geom-violin.r
Expand Up @@ -66,7 +66,7 @@
#' group = round_any(year, 10, floor)) #' group = round_any(year, 10, floor))
#' } #' }
geom_violin <- function (mapping = NULL, data = NULL, stat = "ydensity", position = "dodge", geom_violin <- function (mapping = NULL, data = NULL, stat = "ydensity", position = "dodge",
trim = TRUE, scale = c("area", "count", "width"), ...) { trim = TRUE, scale = "area", ...) {
GeomViolin$new(mapping = mapping, data = data, stat = stat, GeomViolin$new(mapping = mapping, data = data, stat = stat,
position = position, trim = trim, scale = scale, ...) position = position, trim = trim, scale = scale, ...)
} }
Expand Down
6 changes: 3 additions & 3 deletions R/stat-ydensity.r
Expand Up @@ -28,7 +28,7 @@
#' # See geom_violin for examples #' # See geom_violin for examples
#' # Also see stat_density for similar examples with data along x axis #' # Also see stat_density for similar examples with data along x axis
stat_ydensity <- function (mapping = NULL, data = NULL, geom = "violin", position = "dodge", stat_ydensity <- function (mapping = NULL, data = NULL, geom = "violin", position = "dodge",
adjust = 1, kernel = "gaussian", trim = TRUE, scale = c("area", "count", "width"), na.rm = FALSE, ...) { adjust = 1, kernel = "gaussian", trim = TRUE, scale = "area", na.rm = FALSE, ...) {
StatYdensity$new(mapping = mapping, data = data, geom = geom, position = position, StatYdensity$new(mapping = mapping, data = data, geom = geom, position = position,
adjust = adjust, kernel = kernel, trim = trim, scale = scale, adjust = adjust, kernel = kernel, trim = trim, scale = scale,
na.rm = na.rm, ...) na.rm = na.rm, ...)
Expand All @@ -38,12 +38,12 @@ StatYdensity <- proto(Stat, {
objname <- "ydensity" objname <- "ydensity"


calculate_groups <- function(., data, na.rm = FALSE, width = NULL, calculate_groups <- function(., data, na.rm = FALSE, width = NULL,
scale = c("area", "count", "width"), ...) { scale = "area", ...) {
data <- remove_missing(data, na.rm, "y", name = "stat_ydensity", finite = TRUE) data <- remove_missing(data, na.rm, "y", name = "stat_ydensity", finite = TRUE)
data <- .super$calculate_groups(., data, na.rm = na.rm, width = width, ...) data <- .super$calculate_groups(., data, na.rm = na.rm, width = width, ...)


# choose how violins are scaled relative to each other # choose how violins are scaled relative to each other
scale <- match.arg(scale) scale <- match.arg(scale, c("area", "count", "width"))


data$violinwidth <- switch(scale, data$violinwidth <- switch(scale,
# area : keep the original densities but scale them to a max width of 1 # area : keep the original densities but scale them to a max width of 1
Expand Down

0 comments on commit a658737

Please sign in to comment.