5

My code, which was running without problems before, crashed when calling the dcast formula. After playing around, I found out that even the minimal example from the help page of dcast does not work for me anymore. More precisely:

#Air quality example
names(airquality) <- tolower(names(airquality))
aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE)

acast(aqm, day ~ month ~ variable)
acast(aqm, month ~ variable, mean)

The last line produces the following error:

Error in vaggregate(.value = value, .group = overall, .fun = fun.aggregate,  : 
  could not find function ".fun"

Here is my sessionInfo():

R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] C

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.8.9   proto_0.3-9.2   reshape2_1.1    xtable_1.5-6    reshape_0.8.4   plyr_1.5.2      lubridate_0.2.5

loaded via a namespace (and not attached):
[1] stringr_0.5  tools_2.13.1

I don't come up with a satisfying answer of what is going wrong here, so I would appreciate some help. Also, I found the following thread here on stackoverflow: Similar problem This problem seems to result from a custom function. I, however, use the standard mean function and a standard example from the help page.

UPDATE: I just did some internet research and did not find any information regarding an update of the reshape2 package. This was the best guess I had regarding the problem.

UPDATE2: The problem occurred because I most probably reassigned the mean function while I was playing around with a statisctic example during an R session. Restarting R solved the problem. Now, everything works as expected again.

Community
  • 1
  • 1
Christoph_J
  • 6,804
  • 8
  • 44
  • 58
  • This runs fine for me, and the only discernable difference I can see between our systems is that I'm on OS X. – joran Aug 16 '11 at 18:13
  • 1
    Runs fine for me too. I also have R 2.13.1 on win64... What's the output from search()? – Tommy Aug 16 '11 at 18:30
  • Runs fine for me too, Fedora 14 Linux, with `plyr_1.5.2 stringr_0.5 tools_2.13.1`, `reshape2_1.1` and `R version 2.13.1 Patched (2011-07-13 r56380)`. – Gavin Simpson Aug 16 '11 at 19:08
  • @GavinSimpson The `ggplot2` package still depends on `reshape`, so it is perfectly normal to have both `reshape` and `reshape2` loaded in the same session. I have the same config as the OP and don't get the same error. I haven't yet been able to think of a reason for this behaviour. – Andrie Aug 16 '11 at 19:43
  • Thanks @Andrie - was a long shot! – Gavin Simpson Aug 16 '11 at 19:49
  • 3
    Have you tried restarting R and trying the example in a fresh session ? Or do rm(list=ls()) to remove everything from the current session. In the past I have managed to break things by assigning something to something that shouldn't be assigned to. – PaulHurleyuk Aug 16 '11 at 21:36
  • 1
    Thanks @PaulHurleyuk that was exactly the problem. Sorry for not checking that before actually... – Christoph_J Aug 17 '11 at 07:12
  • @PaulHurleyuk Can you post a real "answer" so we can move this off the unanswered questions list? – IRTFM Aug 18 '11 at 05:21

3 Answers3

6

For completeness:

PaulHurleyuk's comment:

Have you tried restarting R and trying the example in a fresh session ? Or do rm(list=ls()) to remove everything from the current session. In the past I have managed to break things by assigning something to something that shouldn't be assigned to.

Christoph_J's response:

Thanks ... that was exactly the problem...

The problem occurred because I most probably reassigned the mean function while I was playing around with a statisctic example during an R session. Restarting R solved the problem. Now, everything works as expected again.

Henry
  • 6,704
  • 2
  • 23
  • 39
0

I ran into this error as well.
Looking at the examples in Help for dcast, the list of args seems to have changed slightly, and it doesn't use fun.aggregate= "function" anymore. Instead, after the formula, you just type the function without quotes.

dcast(aqm, month ~ variable, mean, margins = c("month", "variable"))
treedm
  • 33
  • 5
0

It looks like you have used "mean" as an object and it is still in the workspace. I ran into the same error and it turns out that you only have to clear the objects from the workspace. Try to check it.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33092094) – xilliam Nov 09 '22 at 12:12