Re: [R] xtable - print - suppress output

2009-09-24 Thread David Winsemius


On Sep 24, 2009, at 10:20 AM, Thomas Lumley wrote:


On Mon, 21 Sep 2009, David Winsemius wrote:



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;

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.




If that were true, capture.output() would be pretty useless.  The  
returned value is NULL if the file= argument is specified, otherwise  
it is the captured output.


Thanks for the correction. I was not reading the help page correctly.

table <- capture.output(print(xtable(CERAT), type="html"))  # would  
have been the correct answer.

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-24 Thread Thomas Lumley

On Mon, 21 Sep 2009, David Winsemius wrote:



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.




If that were true, capture.output() would be pretty useless.  The returned 
value is NULL if the file= argument is specified, otherwise it is the captured 
output.

 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Gabor Grothendieck
Note that R has a capture.output function, e.g.

s <- capture.output(print(xtable(BOD), type = "html"))


On Mon, Sep 21, 2009 at 9:21 PM, Charlie Sharpsteen
 wrote:
> On Mon, Sep 21, 2009 at 3:52 PM, Don MacQueen  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]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Charlie Sharpsteen
On Mon, Sep 21, 2009 at 3:52 PM, Don MacQueen  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]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Don MacQueen

I think there is a conceptual issue here.

The xtable() function does not actually create html. What it does is 
add some attributes to the dataframe that is given to it. Here's an 
example:



 tmp <- data.frame( a =1:3, b= c('a','b','c') )
 foo <- xtable(tmp)



 class(foo)

[1] "xtable" "data.frame"

 unclass(foo)

$a
[1] 1 2 3

$b
[1] a b c
Levels: a b c

attr(,"row.names")
[1] 1 2 3
attr(,"align")
[1] "r" "r" "l"
attr(,"digits")
[1] 0 2 2
attr(,"display")
[1] "s" "d" "s"

The output of class(foo) tells us that foo is still a dataframe. It 
has two columns, a and b, just like tmp did. What it also has are 
some additional attributes, in this case some alignment information, 
some "digits" information, and some "display" information. And that 
is *all* that xtable() did.


The real work is done by the function print.xtable(). This takes the 
dataframe and its additional attributes and prints it using either 
html or LaTeX syntax, depending on the 'type' argument. This is why 
xtable() has relatively few optional arguments, but print.xtable() 
has many.  xtable() does not create html. print.xtable() creates html.


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

p.s.
Besides xtable, other packages that help write html include Hmisc 
(already mentioned), hwriter, HTMLUtils, and R2HTML. Maybe one of 
them does things enough differently to do whatever it is you're 
looking for.


At 12:13 AM +0200 9/22/09, Martin Batholdy wrote:

Am 21.09.2009 um 23:59 schrieb Rolf Turner:



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 
are you (explicitly!) using print???   Words fail me!!!

cheers,

Rolf Turner



Because I don't get html code when I only use xtable(xy)





##
Attention: This e-mail message is privileged and confidential. If 
you are not the intended recipient please delete the message and 
notify the sender. Any views or opinions presented are solely those 
of the author.


This e-mail has been scanned and cleared by MailMarshal 
www.*marshalsoftware.com

##


__
R-help@r-project.org mailing list
https://*stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread David Winsemius


On Sep 21, 2009, at 6:13 PM, Martin Batholdy wrote:



Am 21.09.2009 um 23:59 schrieb Rolf Turner:



On 22/09/2009, at 9:52 AM, 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?


If you don't want it printed, then why the 
are you (explicitly!) using print???   Words fail me!!!

cheers,

Rolf Turner



Because I don't get html code when I only use xtable(xy)


One further alternative that is quieter is the html function in Hmisc,  
however this produces a browser page display rather than an R console  
output. It does not output h to the console upon creation


data(tli)
h <- html(tli)
h# the print.html method is part of Hmisc

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Rolf Turner


On 22/09/2009, at 10:13 AM, Martin Batholdy wrote:



Am 21.09.2009 um 23:59 schrieb Rolf Turner:



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 
are you (explicitly!) using print???   Words fail me!!!

cheers,

Rolf Turner



Because I don't get html code when I only use xtable(xy)


Why would you want html code stored in an R object???

I believe, although there is no telling, that what you want
to do is something like:

mung <- xtable(CERAT)
print(mung,file="gorp",type="html")

This will create a *file* of html code that a web browser can use.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Martin Batholdy


Am 21.09.2009 um 23:59 schrieb Rolf Turner:



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 
are you (explicitly!) using print???   Words fail me!!!

cheers,

Rolf Turner



Because I don't get html code when I only use xtable(xy)






##
Attention: This e-mail message is privileged and confidential. If  
you are not the intended recipient please delete the message and  
notify the sender. Any views or opinions presented are solely those  
of the author.


This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com
##


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread David Winsemius


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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] xtable - print - suppress output

2009-09-21 Thread Rolf Turner


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 
are you (explicitly!) using print???   Words fail me!!!

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.