dewittpe / qwraps2

An updated version of qwraps with a focus on flexibility and general purpose. These functions are helpful for extracting and formatting results from R into .Rnw or .Rmd files. Additional functions for routine work such as extracting results from regression models or finding sensitivity and specificity.
http://www.peteredewitt.com/qwraps2/
GNU General Public License v3.0
37 stars 7 forks source link

Exporting or plotting the table? #79

Closed dfsp-spirit closed 5 years ago

dfsp-spirit commented 5 years ago

I guess this is a stupid question and I am overlooking something very obvious, but:

I am using an ordinary R script, not an R markdown document. How can I view the table?

E.g., I would like to make it show up in the Plots panel in rstudio, or export a rendered version to a PDF (or other format) file. I am looking for something like:

t = summary_table(mydata)
plot(t)

The summary_table functions returns markdown code it seems. Am I supposed to write this into a text file, then run knitr on the text file to render to an output file, then open that in PDF software?

dewittpe commented 5 years ago

The object built by summary_table is just a character matrix. There is no plot method for the object and the print method formats for markdown or LaTeX.

If you want to see the table in RStudio I would recommend working in a R Notebook.

image

dfsp-spirit commented 5 years ago

Thanks for your reply. I needed the output as PDF, so I took the LaTeX output and, in a function, added prefix:

    \documentclass{article}
    \begin{document}

and suffix

\end{document}

Then all you have to do is paste it into Kile and click Tex to PDF.

dewittpe commented 5 years ago

Another option for you, if you are looking for pdf as the output write a .Rnw file instead of markdown. a simple example is provided in the example directory. RStudio should knit the .Rnw to .pdf with ease. I don't use RStudio in my day-to-day work so my workflow would have a makefile to run

R --vanilla -e "knitr::knit('<filename>.Rnw')"
latexmk --pdf <filename>.tex
dfsp-spirit commented 5 years ago

That's a great suggestion. If I can do it without rstudio, and without manually starting other GUI applications like Kile, that's of course even better.

liangqiongyue commented 1 year ago

有一个比较曲折的办法可以导出结果到csv中: 下面先展示一下原始的summary_table的结果: image

然后再用这个方法倒一倒就行了:

setwd("D:\\test")
write.table(result, file = "summary_table1", sep = ",", quote = FALSE, row.names = F, fileEncoding = "GBK")
result<-read.table(file = 'summary_table1', header = F, sep = "|", dec = '.', as.is = F, na.strings = "NA", skip = 5, strip.white = T, #comment.char = "T")
                                col.names=c("1", "variable", "mtcars2 (N = 32)", "6 cylinders (N = 7)", "4 cylinders (N = 11)", "8 cylinders (N = 14)", "P-value", "2"))

就是先输出,再以read.table的方式读入,注意对每一列命名一下就行了

dewittpe commented 1 year ago
image image