Permalink
Browse files

Merge commit 'ggplot2-0.9.2.1'

Conflicts:
	DESCRIPTION
	NEWS
  • Loading branch information...
2 parents 24fbbc3 + c0a7b6a commit 5a6919863b6082b148ff75bcdb3392a88f5333bb @wch committed Sep 13, 2012
Showing with 33 additions and 4 deletions.
  1. +9 −0 NEWS
  2. +4 −3 R/scales-.r
  3. +20 −1 inst/tests/test-scales.r
View
9 NEWS
@@ -45,6 +45,15 @@ BUG FIXES
like `math_format()`, and will render them as expressions. (Kohske
Takahashi)
+ggplot2 0.9.2.1
+----------------------------------------------------------------
+
+BUG FIXES
+
+* find_global now searches for objects in the namespace environment
+ instead of the package environment. This fixes problems when ggplot2
+ is imported to another package but not attached.
+
ggplot2 0.9.2
----------------------------------------------------------------
View
@@ -100,15 +100,16 @@ scales_add_defaults <- function(scales, data, aesthetics, env) {
}
# Look for object first in parent environment and if not found, then in
-# ggplot2 package environment. This makes it possible to override default
+# ggplot2 namespace environment. This makes it possible to override default
# scales by setting them in the parent environment.
find_global <- function(name, env) {
if (exists(name, env)) {
return(get(name, env))
}
- if (exists(name, "package:ggplot2")) {
- return(get(name, pkg))
+ nsenv <- asNamespace("ggplot2")
+ if (exists(name, nsenv)) {
+ return(get(name, nsenv))
}
NULL
View
@@ -148,4 +148,23 @@ test_that("scales looked for in appropriate place", {
rm(scale_x_continuous)
p4 <- qplot(mpg, wt, data = mtcars)
expect_equal(xlabel(p4), NULL)
-})
+})
+
+test_that("find_global searches in the right places", {
+ testenv <- new.env(parent = globalenv())
+
+ # This should find the scale object in the package environment
+ expect_identical(find_global("scale_colour_hue", testenv),
+ ggplot2::scale_colour_hue)
+
+ # Set an object with the same name in the environment
+ testenv$scale_colour_hue <- "foo"
+
+ # Now it should return the new object
+ expect_identical(find_global("scale_colour_hue", testenv), "foo")
+
+ # If we search in the empty env, we should end up with the object
+ # from the ggplot2 namespace
+ expect_identical(find_global("scale_colour_hue", emptyenv()),
+ ggplot2::scale_colour_hue)
+})

0 comments on commit 5a69198

Please sign in to comment.