Skip to content
Prev 69796 / 398525 Next

Conflict between xtable and Hmisc when using Sweave?

I tried to follow your suggestions, but without success:

Error: couldn't find function "xtable.mylabel<-"

... resulting from the code below.

Any suggestions?

Thanks,

Sander.


library(xtable)
xtable.mylabel <- get("label", "package:xtable")
library(Hmisc) # provides summarize

set.seed(1)
temperature <- rnorm(300, 70, 10)
month <- sample(1:12, 300, TRUE)
year  <- sample(2000:2001, 300, TRUE)
g <- function(x)c(Mean=mean(x,na.rm=TRUE),Median=median(x,na.rm=TRUE))
summarize(temperature, month, g)

## From Venables and Ripley (2002) p.165.
N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
yield <-c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,
       62.8,55.8,69.5,55.0,
       62.0,48.8,45.5,44.2,52.0,
       51.5,49.8,48.8,57.2,59.0,53.2,56.0)
npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P),
                   K=factor(K), yield=yield)
## to show the effects of re-ordering terms contrast the two fits
tmpAov <- aov(yield ~ block + N * P + K, npk)
tmpTable <- xtable (tmpAov ,
   caption="ANOVA table for vegetation height.")
xtable.mylabel(tmpTable) <- paste("tab:AnovaHeight")
print.xtable(tmpTable, type="latex", floating=TRUE,
   table.placement="h", caption.placement="top",
   latex.environments=c("center"),
   title=first.word(deparse(substitute(object))),
   append=FALSE
   )
Liaw, Andy wrote: