在官员中添加没有列标题的表

时间:2017-09-05 15:26:19

标签: r officer

尝试使用官方在.docx文档中的数据框中添加表,但不包括列标题的行。我已经尝试从数据框中删除列名,然后再将其添加到文档中,但这样做并没有奏效,导致gobbly-gook被添加到顶行而不是顶行而不存在。关于如何实现这一目标的任何想法?

NarrativeDoc <- read_docx()
tmp = data.frame(RowHead1=c('Fact 1','Fact 2'),
                 RowHead2=c("I like chicken","I am not a chicken"),
                 stringsAsFactors =FALSE)
names(tmp)=NULL
NarrativeDoc <- body_add_table(NarrativeDoc,tmp)
print(NarrativeDoc,
      target="C:\\Users\\jclark_v\\Documents\\R\\TestNoHeader.docx")

1 个答案:

答案 0 :(得分:1)

我已将参数标题添加到body_add_table(您需要从github更新)

NarrativeDoc <- read_docx()
tmp = data.frame(RowHead1=c('Fact 1','Fact 2'),
                 RowHead2=c("I like chicken","I am not a chicken"),
                 stringsAsFactors =FALSE)
NarrativeDoc <- body_add_table(NarrativeDoc,tmp, header = FALSE)
NarrativeDoc <- body_add_par(NarrativeDoc, "")
NarrativeDoc <- body_add_table(NarrativeDoc,tmp, header = TRUE)
print(NarrativeDoc,
      target="TestNoHeader.docx")