Skip to content

Conflict between xtable and Hmisc when using Sweave?

7 messages · Liaw, Andy, David B. Dahl, Gabor Grothendieck +1 more

#
You need to add the namespace to the source package, by adding a NAMESPACE
file.  There's an R News article by Prof. Tierney on how to do this.  Also
see the `Writing R Extensions' manual.  You should get the package
maintainer to do that, as that constitute a change in the package source
code.

Short of that, you should make sure that Hmisc is loaded later than xtable,
and use something like what Gabor suggested to access label() in xtable.  (I
would use some other name, though: label() in xtable is already an S3
generic).

Andy
#
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:
#
Sander,

Thanks for pointing out the conflict between Hmisc and xtable.  I am not 
sure I have a good solution.

My understand of the namespace solution is that packages can specify 
which variables to export for use by the package users.  The label 
function is not an internal function, rather one what is intended for 
the user.

Renaming the label() would resolve the conflict with the Hmisc package, 
but make xtable not compatible with previous versions.

As noted by Andy, label() in xtable is an S3 generic with an 
implementation label.xtable() specific to the xtable package.  Perhaps 
Frank of Hmisc might be willing to make his follow the S3 generic naming 
convention?

I am open to suggestions and, more especially, code.  Thanks for using 
xtable.

-- David
Liaw, Andy wrote:

            
#
Using label as an lvalue (i.e. on the left hand side of the assignment)
causes it to refer to a different function, not label itself.  

Any any rate, looking at your example,
it seems that you don't actually need to use Hmisc and xtable at the same time
so just make sure that whichever you want at a particular point
in your code is the only one of the two loaded:

library(Hmisc)
...code that involves Hmisc but not xtable...
detach("package:Hmisc")
library(xtable)
...code that involves xtable but not Hmisc...
On 5/16/05, Sander Oom <sander at oomvanlieshout.net> wrote:
#
Hi David,

Thanks for creating and supporting xtable. Glad I can contribute by 
pointing out problems!

An earlier response from Frank Harrell Jr. suggests that the 
responsibility to resolve the conflict lies primarily with you, as Hmisc 
'was there first'.

Not sure how disputes over package conflicts are generally resolved!?

I'll await a final decision!

Thanks again,

Sander.
David B. Dahl wrote:

  
    
#
I am resending this since I sent it about an hour ago and still have
not seen it appear on R-help.  I assume it never went out but sorry
if it did and you get it twice.
On 5/16/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
#
I did receive it in good order, but the threading on this discussion is 
a bit messy!

I have used your suggestion to temporarily 'attach' and detach Hmisc, 
while I am awaiting a more permanent solution to the conflict.

Thanks,

Sander.
Gabor Grothendieck wrote: