如何删除R中的目录?
在本文中,我们将讨论如何使用 R 编程语言删除目录。
要删除 R 中的目录,我们使用 unlink()。此函数删除命名目录。
Syntax: unlink(directory-name, recursive = BOOLEAN)
Parameter:
- directory-name: a character vector with the names of the directories to be deleted.
- recursive: BOOLEAN TRUE/FALSE, if true directory is deleted recursively otherwise only empty directories are deleted.
Return: It returns normally 0 for success, 1 for failure. Not deleting a non-existent file is not a failure so in that case return 0.
注意:文件命名约定取决于平台。
使用目录:
示例:使用 R 编程语言删除目录
R
# list files or directories in working directory
list.files(path=".", pattern=NULL, all.files=FALSE,
full.names=FALSE)
# delete the directory demo in working directory
unlink("Demo",recursive=TRUE)
# list files or directories in working directory
# after deletion
list.files(path=".", pattern=NULL, all.files=FALSE,
full.names=FALSE)
输出:
运行上述代码后的最终目录: