【问题标题】:Is there a way to change the default overwrite to yes in the write.xlsx function of openxlsx?有没有办法在openxlsx的write.xlsx函数中将默认覆盖改成yes?
【发布时间】:2021-09-19 18:16:15
【问题描述】:

已为新用户分配了在 R Studio 中运行报告的工作,但报告是使用 openxlsx 版本 4.2.3 编写的,而新用户使用的是 openxlsx V 4.2.4。在 4.2.3 中,write.xlsx 函数的默认行为是覆盖现有工作簿,在 4.2.4 中,默认行为是不覆盖现有工作簿。

有没有办法改变这个默认行为,或者我需要重写每个报告中的所有write.xlsx 代码行以包含overwrite = true?

谢谢。

【问题讨论】:

    标签: r overwrite openxlsx


    【解决方案1】:

    一种选择是像这样重新定义write.xlsx。以下表示首先创建一个示例文件,读取该文件,然后使用自定义的write.xlsx 再次写入它,其中我将overwrite = TRUE 设置为默认值。结果没有抛出错误

    library(openxlsx)
    
    # Make an example file
    write.xlsx(head(mtcars), "mtcars.xlsx")
    
    foo <- read.xlsx("mtcars.xlsx")
    
    write.xlsx <- function(x, file) openxlsx::write.xlsx(x, file, overwrite = TRUE)
    
    write.xlsx(foo, "mtcars.xlsx")
    

    reprex package (v2.0.0) 于 2021-07-09 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多