3

I'm trying to get my head around using R to generate reports and think I have settled on trying to just use pander, after confusing myself with various combinations of knitr, Rmarkdown, pander and reports.

I now have two files:

'ReportIntro.brew' that contains the structure of the report

# My Report Title 
## Sample Information
#### <%=set.alignment('left') ; as.character(info[1,1])%>
<%=set.alignment('left') ; info[2:8,1:2]%>

'Report.R' to create a data.frame 'info' required for the report

library(pander) ; library(xlsx)
info=read.xlsx(file="info.xlsx", sheetName="info", header=FALSE)
Pandoc.brew(file="ReportIntro.brew", output=tempfile(), convert="docx")  

This gives me my first Word document, with a table. However, it includes unwanted row and column names. I found a blog about generating tables with pander and knitr, which suggested setting

row.names(info) <- NULL

but this had no effect.

If I try using

print(info[2:8,1:2], include.rownames=FALSE)

or

print(xtable(info[2:8,1:2]), type="html", include.rownames=FALSE)

as suggested in another post about removing row names using xtable, the table doesn't appear at all in the Word doc.

So: how do I get my table without showing row names?

(This is my first post, so I hope it fits the requirements!)

EDIT: This it the result of dput(info)

> dput(info)
structure(list(X1 = c("School Information", "Name", "Type", "DfE number", 
"URN", "DfE link", "Dashboard Report", "Ofsted link", "Test Information", 
"Test Date", "Comments", "Analysis comments", "Sample Size", 
"Year group", "All", "11", "11"), X2 = c(NA, NA, "Primary, Academy, Prep, Middle etc", 
NA, "Enter school URN here", "http://www.education.gov.uk/", 
"http://dashboard.ofsted.gov.uk/", "http://www.ofsted.gov.uk", 
NA, NA, NA, NA, NA, "Set", "All", "top", "middle"), X3 = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "M", "408", "165", 
"243"), X4 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, "F", "402", "145", "257"), X5 = c(NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, "Total", "810", "310", "500")), .Names = c("X1", 
"X2", "X3", "X4", "X5"), row.names = c(NA, 17L), class = "data.frame")
4

1 回答 1

7

我是pander感谢作者@Jerubaal 的尝试。如果您也可以发布info或者更确切地说是 的结果,那就太棒了dput(info),这样我就可以重现您的步骤,但据我所知,一种解决方法是首先将该子集保存info到一个新变量中,然后返回该新对象在一块。

更多细节:如果这些是微不足道的,则抑制,例如从pander到行数的序列。如果您返回 a 的子集,您将返回一个不符合此基本计划的对象。但是如果你创建一个新的,自动的会从to开始。row.names1data.framerow.namesdata.framerow.names1nrow

快速演示(请注意,pander无论如何都会在每个块上自动运行):

> library(pander)
> pander(iris[2:3, 1:3])

---------------------------------------------------
&nbsp;   Sepal.Length   Sepal.Width   Petal.Length 
------- -------------- ------------- --------------
 **2**       4.9             3            1.4      

 **3**       4.7            3.2           1.3      
---------------------------------------------------

> x <- iris[2:3, 1:3]
> pander(x)

---------------------------------------------------
&nbsp;   Sepal.Length   Sepal.Width   Petal.Length 
------- -------------- ------------- --------------
 **2**       4.9             3            1.4      

 **3**       4.7            3.2           1.3      
---------------------------------------------------

> row.names(x) <- NULL
> pander(x)

-------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length 
-------------- ------------- --------------
     4.9             3            1.4      

     4.7            3.2           1.3      
-------------------------------------------

更新:使用提供的info数据集进行演示

> x <- info[2:8,1:2]
> pander(x)

--------------------------------------------------------
&nbsp;         X1                      X2               
------- ---------------- -------------------------------
 **2**        Name                                      

 **3**        Type           Primary, Academy, Prep,    
                                   Middle etc           

 **4**     DfE number                                   

 **5**        URN             Enter school URN here     

 **6**      DfE link      http://www.education.gov.uk/  

 **7**  Dashboard Report http://dashboard.ofsted.gov.uk/

 **8**    Ofsted link       http://www.ofsted.gov.uk    
--------------------------------------------------------

> row.names(x) <- NULL
> pander(x)

------------------------------------------------
       X1                      X2               
---------------- -------------------------------
      Name                                      

      Type           Primary, Academy, Prep,    
                           Middle etc           

   DfE number                                   

      URN             Enter school URN here     

    DfE link      http://www.education.gov.uk/  

Dashboard Report http://dashboard.ofsted.gov.uk/

  Ofsted link       http://www.ofsted.gov.uk    
------------------------------------------------
于 2014-01-09T12:49:42.427 回答