Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R print table using message

Tags:

r

message

I have a dataframe which I want to print as a warning to show NA values.

The reason I can't use print alone is that I am running an RMarkdown document which I want to run without adding this dataframe to the pdf but separately print the dataframe with all my other warning messages in the console.

When I try message(df) it just pastes a long string with all of the columns together and converts dates into numeric.

I tried using message(kable(df)) which was almost perfect but the rows don't appear on new lines. Any suggestions?

like image 461
Anon.user111 Avatar asked Apr 12 '16 13:04

Anon.user111


1 Answers

My guess is you want to use capture.output():

> message(paste0(capture.output(iris), collapse = "\n"))
    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1            5.1         3.5          1.4         0.2     setosa
2            4.9         3.0          1.4         0.2     setosa
3            4.7         3.2          1.3         0.2     setosa
4            4.6         3.1          1.5         0.2     setosa
5            5.0         3.6          1.4         0.2     setosa
...
like image 163
Thomas Avatar answered Oct 24 '22 07:10

Thomas