【问题标题】:Officer package in RR中的官员包
【发布时间】:2020-10-24 02:14:45
【问题描述】:

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

【问题讨论】:

    标签: r officer


    【解决方案1】:

    应该是可以的。如果您知道特定的版本号(您可以查看changelog),只需查看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 包的changelogCRAN 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")
    

    【讨论】:

    • 感谢彼得,您的回复。我检查了更改日志,从 ph_with_* 到 ph_with 的更改是在 0.3.2 版之后完成的。然后我安装了 0.3.2 版本,但出现以下错误 - 错误:“ph_with_flextable_at”已失效。请改用“officer::ph_with”。见 help("Defunct") 另外:警告信息:
    • @AnshulJain 嗨,Anshul,是的,你是对的。看来您还必须安装适当版本的 flextable,即可能是 0.5.6 或更早版本,请参阅他们的 flextable changelogarchive。让我知道这是否有效。
    • 嗨,Petr,官员版本为 0.3.2,灵活表版本为 0.5.6,我遇到了错误。不确定哪两个版本组合兼容-警告:加载“officer”时将以前的导入“zip::unzip”替换为“utils::unzip”错误:“namespace:officer”未导出对象“ph_with”错误:惰性包“flextable”加载失败
    • @AnshulJain 我尝试安装officer 0.3.2flextable 0.4.4(因为它们同时出现)和ph_with_flextable_at() 的基本脚本对我来说正常工作,没有任何警告或错误 - 我有更新了答案,请尝试。
    • 感谢 Petr,您在示例中提到的版本组合运行良好。非常感谢您在这方面的时间。谢谢!
    猜你喜欢
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    • 2018-08-06
    • 1970-01-01
    • 2018-08-12
    • 2021-05-18
    • 2019-06-03
    相关资源
    最近更新 更多