Coerce createTable object to dataframe

396 views
Skip to first unread message

Shmulik Tiosano

unread,
Sep 2, 2015, 3:40:25 PM9/2/15
to compareGroups Forum
Hello,
I would like to know if there is a way to coerce createTable object to a dataframe, in order to present it via knitr in a word notebook.
If i try to use as.data.frame on a createTable class object (e.g., "table_1"), i get the following warning (reproduced from R 3.2.2):
Error in as.data.frame.default(table_1) : 
  cannot coerce class ""compareGroups"" to a data.frame

My final goal, as I mentioned, is to use createTable output to a word notebook, but when I use knitr::kable on a createTable object I get the same warning as mentioned above.

A quick-and-dirty hack I found to solve this problem is to export the createTable to csv by export2csv and then reading it again as dataframe, following by presenting it with knitr::kable elegantly.

Is there a better way to coerce the object to dataframe, or even better - use compareGroups smoothly with knitr?

Thanks!
S.

Isaac Subirana

unread,
Sep 3, 2015, 4:32:28 AM9/3/15
to compareGroups Forum
In the next version of the package (3.1) it will be possible to export tables to markdown format in order to be placed in a Rmd chunks. This function is called export2md. This is not available in CRAN yet but hope it will be soon.
If you need it very urgently, please, email to package mantainer and you will receive this new version.

Isaac.

Shmulik Tiosano

unread,
Sep 5, 2015, 9:58:46 AM9/5/15
to compareGroups Forum
Thank you! It's a great idea, very helpful for my workflow.
No urgency, I'll wait for the CRAN update.
Best,
S.

shylock....@gmail.com

unread,
Apr 22, 2016, 3:18:40 AM4/22/16
to compareGroups Forum
Has this been fixed? I tried using the knitr::kable function and got the same error

Shmulik Tiosano

unread,
Apr 23, 2016, 5:27:44 AM4/23/16
to compareGroups Forum
Yes, just use export2md(), that way you don't have to use kable().

tyl...@gmail.com

unread,
Oct 4, 2016, 11:51:13 PM10/4/16
to compareGroups Forum
Sorry, I'd still be interested in knowing if there was a way to convert directly to a dataframe, since I frequently send data over to Google Docs for sharing. Thanks!
Reply all
Reply to author
Forward
0 new messages