Re: [R] Conflict between xtable and Hmisc when using Sweave?
Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank There are ways to make functions from one area override those from another, but the real solution is to ask the xtable author not to have functions that conflict with the (older) Hmisc package. -Frank -- Dr Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Conflict between xtable and Hmisc when using Sweave?
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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank There are ways to make functions from one area override those from another, but the real solution is to ask the xtable author not to have functions that conflict with the (older) Hmisc package. -Frank -- Dr Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conflict between xtable and Hmisc when using Sweave?
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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank There are ways to make functions from one area override those from another, but the real solution is to ask the xtable author not to have functions that conflict with the (older) Hmisc package. -Frank -- Dr Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conflict between xtable and Hmisc when using Sweave?
Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank There are ways to make functions from one area override those from another, but the real solution is to ask the xtable author not to have functions that conflict with the (older) Hmisc package. -Frank -- Dr Sander P. Oom Animal, Plant and Environmental
Re: [R] Conflict between xtable and Hmisc when using Sweave?
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 [EMAIL PROTECTED] wrote: Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5)
RE: [R] Conflict between xtable and Hmisc when using Sweave?
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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y,
Re: [R] 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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight )
Re: [R] Conflict between xtable and Hmisc when using Sweave?
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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell
Re: [R] Conflict between xtable and Hmisc when using Sweave?
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: 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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting code? I will gladly test the new package! I have tried latex(Hmisc) to export the anova table, but results are not promising! I prefer xtable!! Thanks, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top,
RE: [R] Conflict between xtable and Hmisc when using Sweave?
For fixing the problem you have, you need: xtable.mylabel- - get(label-.xtable, package:xtable) I.e., you need the replacement function. One possibility of resolving the conflict, as I communicated with Frank, is to make label() and label-() in Hmisc the S3 default methods, as xtable defines the methods for xtable, but provided no default methods. This probably has the minimal impact (if any) on backward compatibility in both packages. BTW, you should call print() rather than print.xtable(). Andy From: Sander Oom 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: 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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment! Would you be able to correct the conflicting
Re: [R] Conflict between xtable and Hmisc when using Sweave?
That seems like a good solution. The one problem is that both packages would need their own label generic functions if they are to operate independently of each other so if they were both loaded the last one loaded would give a warning that the label generic from the first loaded package is being masked. Of course, that does not really matter since the two label generics would be identical but it would be slightly annoying. One way around that would be to have one of the packages depend on the other so that they share the label generic although I am not sure that the two authors really would want that. Another way around that would be for the R core to include the label generic so that both packages can leverage off the core but that would require some additional co-operation. On 5/16/05, Liaw, Andy [EMAIL PROTECTED] wrote: One possibility of resolving the conflict, as I communicated with Frank, is to make label() and label-() in Hmisc the S3 default methods, as xtable defines the methods for xtable, but provided no default methods. This probably has the minimal impact (if any) on backward compatibility in both packages. BTW, you should call print() rather than print.xtable(). Andy From: Sander Oom 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: 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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: Even without a namespace
Re: [R] Conflict between xtable and Hmisc when using Sweave?
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 [EMAIL PROTECTED] wrote: 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: 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 From: Sander Oom Hi Andy and Gabor, Thanks for your help so far! I am discovering another R dimension. Trying to put my head around all thisthe 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: 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 [EMAIL PROTECTED] wrote: 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 From: Of Sander Oom Dear David, I would like to use summarize(Hmisc) and print.xtable(xtable) in a single Sweave document, but a conflict with the 'label' function prohibits this at the moment!
[R] Conflict between xtable and Hmisc when using Sweave?
Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R -- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conflict between xtable and Hmisc when using Sweave?
Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conflict between xtable and Hmisc when using Sweave?
Dear Frank, I have a Sweave document in which I export anova (aov) tables to Latex and calculate some summary statistics with summarize{Hmisc} for a graph (as in the example below). I currently use the following code for the aov tables: results=tex= tmp - datGrassHC[datGrassHC$Loc 0 datGrassHC$Loc 9 ,] tmpAov - aov(Height~Geology*Altitude*Origin*BinInOut , data=tmp) tmpTable - xtable (tmpAov , caption=ANOVA table for vegetation height., label=tab:AnovaHeight ) print.xtable(tmpTable, type=latex, floating=TRUE, table.placement=ht, caption.placement=top, latex.environments=c(center)) ) @ I used xtables, because it has a working aov example. I would be happy to use an alternative if I knew how! Would you have sample code to illustrate how to export an aov table to Latex using latex{Hmisc}. Thanks very much for your help, Sander. Frank E Harrell Jr wrote: Sander Oom wrote: Dear R users, The Sweave code below runs fine, as it is. However, an error occurs when the line 'library(xtable)' is uncommented: Error: chunk 1 Error in label-(`*tmp*`, value = month) : no applicable method for label- Is anybody aware of this and knows a workaround? Thanks, Sander. *** \documentclass[a4paper]{article} \title{Sweave Test for summarize} \author{Sander Oom} \usepackage{a4wide} \begin{document} \maketitle \begin{figure}[ht] \begin{center} fig=TRUE,echo=FALSE= # library(xtable) library(Hmisc) set.seed(111) dfr - expand.grid(month=1:12, year=c(1997,1998), reps=1:100) month - dfr$month year - dfr$year y - abs(month-6.5) + 2*runif(length(month)) + year-1997 s - summarize(y, llist(month,year), smedian.hilow, conf.int=.5) print(xYplot(Cbind(y,Lower,Upper) ~ month, groups=year, data=s, keys='lines', method='alt', type='b')) @ \end{center} \end{figure} \end{document} version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor1.0 year 2005 month04 day 18 language R I feel this is an xtable problem because Hmisc has being using label and label- since 1991. Frank -- Dr. Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html