Skip to contents

Delete files and directories

Usage

unlink2(x)

Arguments

x

character. Files or directories to be deleted. Unlink base unlink, these must exist on disk or the function will intentionally error.

Value

integer(1). 0 for success, 1 for failure, invisibly.

Details

This variant hardens file path handling, for better Windows compatibility.

Note

Updated 2022-06-08.

Examples

tempdir <- tempdir2()
x <- file.path(tempdir, "file.txt")
y <- file.path(tempdir, "directory")
invisible(file.create(x))
invisible(dir.create(y))
out <- unlink2(c(x, y))
print(out)
#> [1] 0