R test if a file exists, and is not a directory

前端 未结 3 904
[愿得一人]
[愿得一人] 2021-01-07 22:21

I have an R script that takes a file as input, and I want a general way to know whether the input is a file that exists, and is not a directory.

In Python you would

3条回答
  •  礼貌的吻别
    2021-01-07 23:10

    There is a dir.exists function in all recent versions of R.

    file.exists(f) && !dir.exists(f)
    

提交回复
热议问题