Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Fix: import reshape2 instead of reshape #17

merged 5 commits into from

3 participants


This should solve issue #15 , hope this helps :)


No, that's no enough. You have to run the test, for example variable_name is in reshape2


Great: so where are the unit tests that I can run? I can't find any.


Build the package which includes an example; there are no unit tests, but a full build/check for CRAN includes this.


Thanks. Weird: I had compiled the package, but didn't see the test. I probably had a no-check flag somewhere, or didn't pay attention. Will get back to it.


PS: I've asked on manipulatr mailing list for any info on broken backward compatibility between reshape and reshape2.


Instead wasting too many grey cells on the check-flags, use RStudio, create a package project, and Build/Check. I also suggest to explicitly check "roxygenize on Build and Reload", because that what one easily forgets.

The only other change is the _/. in But there is also the problem with Rhat and 1 chain, and the nasty histogram warnings.


Thanks Dieter. Looks like there's also cast() which has been renamed acast/dcast depending on the use. The warnings do not worry me so much: they are ugly indeed, but apparently can be fixed.

jucor added some commits
@jucor jucor Replace cast() by dcast() from reshape2 4e76705
@jucor jucor Replace X1/X2 by Var1/Var2
reshape2's melt() names its columns Var1/Var2
while reshape used to name them X1/X2

Fixed the _/., the cast(), and a naughty melt() issue, too. Now the check passes smoothly, and doesn't raise any histogram warnings. Could you please give me examples to reproduce:

  • the histogram warnings
  • the problem of Rhat with 1 chain ?

If you add them as standalone files and pull-request on my fork jucor/ggmcmc , I will turn them into unit tests and work from there. Thanks!


You should see the histogram-warning when compiling the standard example. It comes from ggs_histogram/geom_histogram. I suggest the following changes, but cannot get it to work since I do not know the syntax (code below fails in geom_histogram).
Feel free to check:

breaks = tapply(D$value,D$Parameter,function(x){
pretty(range(x), n = nclass.FD(x), min.n = 1)
f <- ggplot(D, aes(x=value) ) +
geom_histogram(breaks=breaks) +
facet_wrap(~ Parameter, ncol=1, scales="free")


When trying to reproduce the 1-chain problem, I encountered another one which I remember had to do with some coda-related problems; I had already solved that once, but don't remember the details. See Issue #18. Sorry, I have to leave, cannot work on this one currently.


Thanks for your help Dieter! I'll fix what I can/need, and contact @xfim to see if he can pull.


The problem with the multiple binwidths appears to be that breaks can only specify common breaks for all variables. There are a few workarounds, but the desagreement of the warning is small enough and the effort to high for me to push further :-) I suggest filling a separate issue.


Bottom line: the port to reshape2 is done here. The Rhat with 1 chain is also a separate problem (that I'll be glad to look into, too), but at least this issue is ripe for merging. Emailing @xfim. Thanks for the input Dieter!

@xfim xfim merged commit 6a991d0 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2013
  1. @jucor
Commits on Jun 24, 2013
  1. @jucor

    Fix variable_name ->

    jucor authored
    Thanks Dieter Menne for pointing this out.
  2. @jucor

    Automatic reorder by Roxygen2

    jucor authored
  3. @jucor
  4. @jucor

    Replace X1/X2 by Var1/Var2

    jucor authored
    reshape2's melt() names its columns Var1/Var2
    while reshape used to name them X1/X2
This page is out of date. Refresh to see the latest.
@@ -11,7 +11,7 @@ Maintainer: Xavier Fernández i Marín <>
Author: Xavier Fernández i Marín <>
- reshape,
+ reshape2,
@@ -1,7 +1,5 @@
@@ -9,9 +7,11 @@ export(ggs_crosscorrelation)
2  R/ggs.R
@@ -116,7 +116,7 @@ ggs_chain <- function(s) {
# Prepare the dataframe
d <- data.frame(Iteration=iter, as.matrix(unclass(s)))
- D <- melt(d, id.vars=c("Iteration"), variable_name="Parameter")
+ D <- melt(d, id.vars=c("Iteration"),"Parameter")
# Revert the name of the parameters to their original names
levels(D$Parameter) <- name.chains
4 R/ggs_caterpillar.R
@@ -58,7 +58,7 @@ ggs_caterpillar <- function(D, family=NA, X=NA,
dc <- ddply(D[[i]], .(Parameter), summarize,
q=quantile(value, probs=qs), qs=qs)
dc$qs <- factor(dc$qs, labels=names(qs))
- dcm <- cast(dc, Parameter ~ qs, value=.(q))
+ dcm <- dcast(dc, Parameter ~ qs, value=.(q))
D[[i]] <- dcm # replace list element with transformed list element
@@ -79,7 +79,7 @@ ggs_caterpillar <- function(D, family=NA, X=NA,
q=quantile(value, probs=qs), qs=qs,
dc$qs <- factor(dc$qs, labels=names(qs))
- dcm <-, Parameter ~ qs, value=.(q)))
+ dcm <-, Parameter ~ qs, value=.(q)))
10 R/ggs_crosscorrelation.R
@@ -18,15 +18,15 @@ ggs_crosscorrelation <- function(D, family=NA, absolute.scale=TRUE) {
if (attributes(D)$nParameters <= 1) {
stop("Can't calculate crosscorrelations with a single chain")
- X <- cast(D, Iteration + Chain ~ Parameter)
+ X <- dcast(D, Iteration + Chain ~ Parameter)
# Chain management is not easy <- melt(cor(as.matrix(X[,-c(1, 2)])))
# Need to revert parameter names
-$X1 <- factor($X1, labels=levels(D$Parameter))
-$X2 <- factor($X2, labels=levels(D$Parameter))
-$value[$$X2] <- NA
+$Var1 <- factor($Var1, labels=levels(D$Parameter))
+$Var2 <- factor($Var2, labels=levels(D$Parameter))
+$value[$$Var2] <- NA
# Plot
- f <- ggplot(, aes(x=X1, y=X2)) +
+ f <- ggplot(, aes(x=Var1, y=Var2)) +
geom_tile(aes(fill=value)) +
xlab("") + ylab("") + theme(axis.text.x=element_text(angle=90))
if (absolute.scale) {
6 R/ggs_geweke.R
@@ -41,9 +41,9 @@ ggs_geweke <- function(D, family=NA, frac1=0.1, frac2=0.5) {
# Cast the dataframe in pieces to have the data arranged by parameter, chain
# and first and last
- M <- cast(D.geweke, Parameter + Chain ~ part, value=.(m))
- N <- cast(D.geweke, Parameter + Chain ~ part, value=.(n))
- SDE0F <- cast(D.geweke, Parameter + Chain ~ part, value=.(sde0f))
+ M <- dcast(D.geweke, Parameter + Chain ~ part, value=.(m))
+ N <- dcast(D.geweke, Parameter + Chain ~ part, value=.(n))
+ SDE0F <- dcast(D.geweke, Parameter + Chain ~ part, value=.(sde0f))
# Reorganize the z scores
Z <- data.frame(Parameter=M$Parameter, Chain=M$Chain,
z= (M$first - M$last) /
2  R/globals.R
@@ -8,7 +8,7 @@ if (base::getRversion() >= "2.15.1") {
"Lag", "Autocorrelation", # from ggs_autocorrelation
"thick.low", "thick.high", "thin.low", "thin.high", # from ggs_caterpillar
"part_chain", # for ggs_compare_partial
- "X1", "X2", # for ggs_crosscorrelation
+ "Var1", "Var2", # for ggs_crosscorrelation
"n", "z", "part", # for ggs_geweke
"m" # for ggs_geweke and ggs_running
2  R/help.R
@@ -7,7 +7,7 @@
#' results against observed variables.
#' @references \url{}.
-#' @import plyr ggplot2 reshape
+#' @import plyr ggplot2 reshape2
#' @docType package
#' @name ggmcmc
#' @aliases ggmcmc ggmcmc-package
Something went wrong with that request. Please try again.