R中的官员包

Officer package in R

所有 ph_with_* 函数都已弃用。如果我仍然可以使用旧版本的 officer 和 flextable,有什么办法可以让我使用 ph_with_* 函数。我有一个自动化流程,由于是新版本,我很难进行所有更改

应该是可以的。如果您知道特定的版本号(您可以检查 changelog), just look to the archive,复制您的版本的 URL 和 运行 例如:

install.packages("https://cran.r-project.org/src/contrib/Archive/officer/officer_0.1.0.tar.gz",
                 repos = NULL, type = "source")

或使用devtools包:

devtools::install_version("officer",
                          version = "0.1.0",
                          repos = "http://cran.r-project.org")

flextable 软件包及其 changelog and CRAN archive 也是如此。

例子

我试过以下方法:

devtools::install_version("officer",
                          version = "0.3.2",
                          repos = "http://cran.r-project.org")
devtools::install_version("officer",
                          version = "0.4.4",
                          repos = "http://cran.r-project.org")

文档中带有 ph_with_flextable_at() 的示例可以正常工作:

library(officer)
library(flextable)
ft <- flextable(head(mtcars))

doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content",
                 master = "Office Theme")
doc <- ph_with_flextable(doc, value = ft, type = "body")
doc <- ph_with_flextable_at(doc, value = ft, left = 4, top = 5)
print(doc, target = "test.pptx")