我正在尝试使用openxlsx
编写文件:
saveWorkbook(wb, file=filename, overwrite=T)
没有给我错误,但没有文件出现,而
> saveWorkbook(wb, file=filename, overwrite=F)
Error in saveWorkbook(wb, file = filename, overwrite = F) :
File already exists!
我可以在 R 中清楚地看到 t6his:
> filename
[1] "/home/balter/miseq-239/analysis/beta_diversity//tables/miseq-239_beta_diversity_Genus_clust_unifrac_permanova.xlsx"
> filedir = gsub('\/[^/]+$', '', filename)
> filedir
[1] "/home/balter/miseq-239/analysis/beta_diversity//tables"
> file.exists(filename)
[1] TRUE
> list.files(path=filedir)
character(0)
这是怎么回事?
我似乎无法通过模拟来复制这个问题。 您确定文件未创建的程度如何(例如,您可以在saveWorkbook
后立即运行file.exists
吗? 我会更新openxlsx
,看看您是否可以在新会话中复制此示例。
library(openxlsx)
wb <- createWorkbook("Creator of workbook")
addWorksheet(wb, sheetName = "My first worksheet")
tmp <- tempfile(fileext = ".xlsx")
# Create when file does not exist [overwrite = TRUE]
file.exists(tmp)
#> [1] FALSE
saveWorkbook(wb, file = tmp, overwrite = TRUE)
#> Note: zip::zip() is deprecated, please use zip::zipr() instead
file.exists(tmp)
#> [1] TRUE
# Create when file does not exist [overwrite = FALSE]
file.remove(tmp)
#> [1] TRUE
file.exists(tmp)
#> [1] FALSE
saveWorkbook(wb, file = tmp, overwrite = FALSE)
file.exists(tmp)
#> [1] TRUE
# Create when file exists [overwrite = TRUE]
file.exists(tmp)
#> [1] TRUE
saveWorkbook(wb, file = tmp, overwrite = TRUE)
file.exists(tmp)
#> [1] TRUE
# Create when file exists [overwrite = FALSE]
file.exists(tmp)
#> [1] TRUE
saveWorkbook(wb, file = tmp, overwrite = FALSE)
#> Error in saveWorkbook(wb, file = tmp, overwrite = FALSE): File already exists!
file.exists(tmp)
#> [1] TRUE
sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-apple-darwin18.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.6
#>
#> Matrix products: default
#> BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.7/lib/libopenblasp-r0.3.7.dylib
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] openxlsx_4.1.0.1
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_3.6.1 magrittr_1.5 tools_3.6.1 htmltools_0.4.0
#> [5] yaml_2.2.0 Rcpp_1.0.2 stringi_1.4.3 rmarkdown_1.16
#> [9] highr_0.8 knitr_1.25 stringr_1.4.0 xfun_0.10
#> [13] digest_0.6.21 zip_2.0.4 rlang_0.4.0 evaluate_0.14
创建于 2019-10-15 由 reprex 软件包 (v0.3.0(