scales package and the development version

46 views
Skip to first unread message

Brian Diggs

unread,
Aug 8, 2011, 6:46:23 PM8/8/11
to ggplot2
In the development version of ggplot2, are you expected to make your own
call to libarary("scales") to get certain things to work? I was playing
with the new date scales and ran into problems with the examples when
scales wasn't loaded.

# To get the develop version on my system
# library("devtools")
# dev_mode()
library("ggplot2")
example("scale_x_date")

Gives the output:

> library("ggplot2")
Loading required package: proto
> example("scale_x_date")

scl_x_> # We'll start by creating some nonsense data with dates
scl_x_> df <- data.frame(
scl_x_+ date = seq(Sys.Date(), len=100, by="1 day")[sample(100, 50)],
scl_x_+ price = runif(50)
scl_x_+ )

scl_x_> df <- df[order(df$date), ]

scl_x_> dt <- qplot(date, price, data=df, geom="line") +
opts(aspect.ratio = 1/4)

scl_x_> # We can control the format of the labels, and the frequency of
scl_x_> # the major and minor tickmarks. See ?format.Date and ?seq.Date
scl_x_> # for more details.
scl_x_> dt + scale_x_date()
Waiting to confirm page change...

scl_x_> dt + scale_x_date(labels = date_format("%m/%d"))
Error in structure(list(call = match.call(), aesthetics = aesthetics, :
could not find function "date_format"


date_format (and date_breaks used later in the example) are in the
scales package, but ggplot2 just imports scales, not depends on scales.

Are we expected to do our own loading of scales? If so, should the
examples be changed to call scales:::date_format?

If I call

library("scales")

Then the example runs fine (*).

(*) [At least, it doesn't error due to that. The example also contains
a melt, which is from reshape/reshape2 which is also just imported and
not attached. When it gets to that, it errors. Same problem, but
reshape/reshape2 is not coupled so tightly to ggplot2, that I would
expect that it must be available. Still, the examples would need to be
changed so they run without error.]


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Hadley Wickham

unread,
Aug 8, 2011, 11:26:32 PM8/8/11
to Brian Diggs, ggplot2
> In the development version of ggplot2, are you expected to make your own
> call to libarary("scales") to get certain things to work?

Yes.

> Are we expected to do our own loading of scales?  If so, should the examples
> be changed to call scales:::date_format?

Well it would be scales::date_format because it's exported, but the
examples should explicitly load the scales package when needed.

> (*) [At least, it doesn't error due to that.  The example also contains a
> melt, which is from reshape/reshape2 which is also just imported and not
> attached.  When it gets to that, it errors.  Same problem, but
> reshape/reshape2 is not coupled so tightly to ggplot2, that I would expect
> that it must be available.  Still, the examples would need to be changed so
> they run without error.]

Please feel free to file bug reports whenever you notice this,
although I think we should pick those problems up as we get closer to
passing R CMD check.

Hadley


--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages