如何从officer中删除docx开头的空行

如何从officer中删除docx开头的空行,r,officer,R,Officer,我正在使用officerforR创建一个Word(docx)文档。代码如下: library(officer) library(magrittr) my_docx = read_docx() %>% # cursor_begin() %<>% body_add_par("Hello here is a test sentence to see if there is a blank line above it.", style = "Normal") %>%

我正在使用
officer
for
R
创建一个Word(docx)文档。代码如下:

library(officer)
library(magrittr)

my_docx = read_docx() %>% 
  # cursor_begin() %<>% 
  body_add_par("Hello here is a test sentence to see if there is a blank line above it.", style = "Normal") %>% 
  print(target = "test.docx")
图书馆(官员)
图书馆(magrittr)
my_docx=读取_docx()%>%
#光标_begin()%%
body_add_par(“您好,这是一个测试句子,看看上面是否有空行。”,style=“Normal”)%>%
打印(target=“test.docx”)
它创建了一个docx文档,在句子上方有一个空行。它不是在字体样式中设置的字体样式前的间距。我没有注释<代码> CURSORIX()/代码>,但空白行保留。我怎样才能摆脱这个


感谢您的帮助

要删除段落,需要使用函数
body\u remove()
。请参阅此处的文档:

图书馆(官员)
图书馆(magrittr)
我的_docx%
光标\u begin()%%>%body\u remove()%%
body_add_par(“你好,这是一个测试句子,看看上面是否有一个空行。”,
style=“Normal”)%%>%
打印(target=“test.docx”)

body\u add\u par
中有一个
pos
参数,我缺少该参数,可以将其设置为
之前的
,这将调整docx文档中文本的位置…我的错。谢谢!我不需要删除一个段落,因为我是从一个空白模板开始的……我忽略的只是
body\u add\u par
中的游标位置参数,现在看起来很傻,因为我没有完全阅读文档……谢谢
officer
您能验证我的解决方案吗?这回答了你原来的问题。
library(officer)
library(magrittr)

my_docx <- read_docx() %>% 
  cursor_begin() %>% body_remove() %>% 
  body_add_par("Hello here is a test sentence to see if there is a blank line above it.", 
               style = "Normal") %>% 
  print(target = "test.docx")