gpt4 book ai didi

r - 通过 Rmarkdown 添加 MS Word 注释

转载 作者:行者123 更新时间:2023-12-02 02:43:09 25 4
gpt4 key购买 nike

有没有办法通过 R Markdown 文件添加 MS Word“评论”?我正在使用 reference_docx,并且熟悉添加自定义样式......但还没有想出如何让评论显示在这样的一边:

enter image description here

澄清一下:我想在我的纯文本 Rmd 文件中添加一个标签(或其他什么?),这样当我“编织”生成的 MS Word 文档时,就会有一个呈现的评论。

最佳答案

实际上,这是可能的。是的,Markdown(和 RMarkdown)用于纯文本书写,但它们是使用 pandoc 进行翻译的。所以我用谷歌搜索了这个并找到了以下代码,效果很好:

---
title: "test"
output:
word_document: default
---

This text contains a [This is the comment]{.comment-start id="0" author="Johannes G." date="2020-01-13T10:12:00Z"}comment.[]{.comment-end id="0"}.
enter image description here
当编织到其他格式时,这会造成一些困惑,因此您可能需要考虑使用 R函数代替:
```{r echo=FALSE}
word_comment <- function(comment, highlight = "") {
if (isTRUE(knitr:::pandoc_to() == "docx")) {
paste0('[', comment, ']{.comment-start id="0" author="Johannes G."',
'date="2020-01-13T10:12:00Z"}', highlight, '[]{.comment-end id="0"}')
}
}
```

This text contains a `r word_comment("This is the comment", "comment.")`.
代码可能会得到改进,但我找不到创建注释的块的文档,所以目前它工作得很好。

关于r - 通过 Rmarkdown 添加 MS Word 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57892419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com