hi, I use xtable to convert data.frames to html tables. But when I use the print-command I always get the whole output printed even if I just want to save the html table into a variable; table <- print(xtable(CERAT), type="html") How can I suppress that output is printed? thanks! [[alternative HTML version deleted]]
On 22/09/2009, at 9:52 AM, Martin Batholdy wrote:> hi, > > > > I use xtable to convert data.frames to html tables. > But when I use the print-command I always get the whole output printed > even if I just want to save the html table into a variable; > > table <- print(xtable(CERAT), type="html") > > > How can I suppress that output is printed?If you don't want it printed, then why the <expletive deleted> are you (explicitly!) using print??? Words fail me!!! cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
On Sep 21, 2009, at 5:52 PM, Martin Batholdy wrote:> > I use xtable to convert data.frames to html tables. > But when I use the print-command I always get the whole output printed > even if I just want to save the html table into a variable; > > table <- print(xtable(CERAT), type="html") > > > How can I suppress that output is printed?Perhaps by diverting it somewhere else? (after the example in xtable's help page) capture.output(print(tli.table, type="html"), file="HTout.html") R is not an HTML editor, so it would seem less than intuitive to send it to a character variable. It would not work to assign the value of capture.output since that is an invisible NULL. -- David Winsemius, MD Heritage Laboratories West Hartford, CT
On Mon, Sep 21, 2009 at 3:52 PM, Don MacQueen <macq@llnl.gov> wrote: snip...> In other words, there is no such thing as saving the html table into a > variable. It just doesn't work that way. All that is possible is to write it > (print it) to either the screen or a file. > > Which leads back to the question that one of the other responses asked ... > what is the reason for saving it to an R object? What do you hope to > accomplish by doing that, that you can't accomplish using print() ? > > Hope this helps > > -Don > >Actually, I find myself doing this all the time with xtable output. xtable() is a very nice piece of code and it has saved me a lot of time-- but in some cases I have found the defaults/options available for output formatting rather... inflexible. The quickest solution for me has always been to capture the output of print.xtable() as an R character vector, do some editing/splicing/tweaking and then re-emit the code. I use a tweaked version of the print.xtable function that omits the final print() statement (which is what causes all the output to hit the console, or your LaTeX document or wherever else you don't want it to go) and reorganizes the output for easy editing. You can make your own using: myXtable <- edit( xtable:::print.xtable ) Then replace the lines: print(result) return(invisible(result$text)) With: result$text <- strsplit( result$text, '\n' )[[1]] return( result$text ) Now, you can use output <- myXtable( xtableObject, type = 'html' ) To capture the output as a character vector and edit it as you wish. Hope that helps! -Charlie [[alternative HTML version deleted]]