【问题标题】:file.remove gives "cannot remove file ... reason 'No such file or directory'" although I use "showWarnings = FALSE"file.remove 给出“无法删除文件......原因'没有这样的文件或目录'”虽然我使用“showWarnings = FALSE”
【发布时间】:2015-07-08 11:23:47
【问题描述】:

在从 cmd.exe(在 Windows 上)运行的(非交互式)R 脚本中,我有以下行

file.remove('text.xls', showWarnings = FALSE)

当解释器到达这一行并且文件不存在时,它会写

cannot remove file 'text.xls', reason 'No such file or directory'

虽然我特意将参数showWarnings设置为FALSE。有没有办法禁止显示此消息?

【问题讨论】:

  • 如果它是一个交互式脚本会有什么不同吗?

标签: r file cmd


【解决方案1】:

您可以添加if声明:

if(file.exists("text.xls"))
    file.remove('text.xls', showWarnings = FALSE)

所以file.remove函数只有在指定的文件存在时才会被评估

【讨论】:

  • file.remove() 描述应该明确这个条件,而不是抛出“没有这样的文件或目录”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-17
  • 1970-01-01
  • 2022-01-15
  • 2021-09-01
  • 2019-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多