18

In following Hadley Wickham's "Practical tools for exploring data and models" examples in section 2.4, Casting molten data I'm getting Error: could not find function "cast". I have the reshape2 package installed and loaded.

> cast(msmithsm, time + subject ~ variable)
Error: could not find function "cast"
Jack Frost
  • 2,151
  • 3
  • 17
  • 21

2 Answers2

24

In reshape2, cast() has been replaced by two functions: acast() and dcast().

From ?cast, in package reshape2:

Description:

Use ‘acast’ or ‘dcast’ depending on whether you want vector/matrix/array output or data frame output.

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • Seems kind of crazy that ?cast works & does not explicitly note that `cast` does not exist! – Drew Steen Mar 07 '13 at 18:45
  • @DrewSteen -- I guess in this case, `?cast` is more like `?Arithmetic` or `?Startup`, describing a topic rather than a function. – Josh O'Brien Mar 07 '13 at 19:03
  • 4
    I understand what you're saying, but I think the documentation would be improved by either explicitly noting that `cast` - the way it reads, it is easy to come away understanding that `acast` and `dcast` are related alternative functions. – Drew Steen Mar 07 '13 at 19:47
2

Had related issue (Error: could not find function "dcast"). I had old library, library(plyr), so just added to code...

install.packages("reshape2") # may already be installed
library(reshape2)

Then dcast worked again

Dan Tarr
  • 209
  • 3
  • 8