Skip to content

Conflict between xtable and Hmisc when using Sweave?

4 messages · Liaw, Andy, Sander Oom, Gabor Grothendieck

#
One possible solution without renaming the functions is to add namespace to
either xtable or Hmisc.  Given the size of Hmisc, it probably would be much
easier to do that with xtable.

With namespace in xtable, you can do xtable:::label() to refer to the
label() in xtable specifically.

Andy
#
Even without a namespace one could explicitly reference the label
in xtable via:

xtable.label <- get("label", "package:xtable")
On 5/16/05, Liaw, Andy <andy_liaw at merck.com> wrote:
#
Hi Andy and Gabor,

Thanks for your help so far! I am discovering another R dimension.

Trying to put my head around all this....the conflict actually exposes 
itself when calling summarize(Hmisc). Summarize(Hmisc) calls label 
internally, so I can not call it explicitly. Simply calling 
label(xtable) explicitly will not solve the problem with summarize(Hmisc).

Thus, I should use namespaces as Andy is suggesting. Now I just need to 
know how I 'add namespace' to a library? Does 'loadNamespace' have 
something to do with it?

Thanks very much for your help!

Sander.


## 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="Test export of ANOVA table.",
   label="tab:Anova")
print.xtable(tmpTable, type="latex", floating=TRUE,
   table.placement="h", caption.placement="top",
   latex.environments=c("center"))

Alternatively, using namespace for xtable:

tmpTable <- xtable(tmpAov , caption="Test export of ANOVA table.")
xtable:::label(tmpTable) <- paste("tab:Anova")
print.xtable(tmpTable, type="latex", floating=TRUE,
   table.placement="ht", caption.placement="top",
   latex.environments=c("center"))
Gabor Grothendieck wrote:

  
    
#
Do you need label in both xtable and Hmisc?  If you only need
it in Hmisc and not in xtable then just be sure you have loaded
xtable first and Hmisc second.  This:

search()

will give you the search path.  It will find the first one on the
search path so if Hmisc is before xtable (which would occur
if you loaded Hmisc last) then it would find that one.

If you have already loaded them in the wrong order then just
detach Hmisc and load it again:

detach("package:Hmisc")
library(Hmisc)
On 5/16/05, Sander Oom <slist at oomvanlieshout.net> wrote: