如何使用 library(writexl) 包以自定义名称保存多个数据框

How to use library(writexl) pakcage to save multiple dataframe with a custmized name

我正在使用包 writexl 将两个数据帧保存到 R shiny 中的一个 csv 文件中。

这是我的部分代码:

library(writexl)
server <- function(input,output){
    filename = function(){
              paste('data.csv')
            },
    content = function(file){
    df1  <- ...
    df2 <- ...
    write_xlsx(list(df1,df2), file) 
        }
      )

此代码适用于我,但您知道如何为 df1 和 df2 提供自定义 sheet 名称吗?我不想更改包,只想使用 "write_xlsx",而不是 "write.xlsx"

只需在列表中命名数据框即可。

write_xlsx(list(df1 = df1, df2 = df2), file)

嗨,我刚刚解决了:

write_xlsx(list("sheet name1" = df1, "sheet name2" = df2), file)