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()
#> Error in vapply(X = X, FUN = FUN, FUN.VALUE = logical(1L), ..., USE.NAMES = useNames): formal argument "USE.NAMES" matched by multiple actual arguments
x <- file.path(tempdir, "file.txt")
#> Error in file.path(tempdir, "file.txt"): cannot coerce type 'closure' to vector of type 'character'
y <- file.path(tempdir, "directory")
#> Error in file.path(tempdir, "directory"): cannot coerce type 'closure' to vector of type 'character'
invisible(file.create(x))
#> Error: object 'x' not found
invisible(dir.create(y))
#> Error: object 'y' not found
out <- unlink2(c(x, y))
#> Error: object 'x' not found
print(out)
#> Error: object 'out' not found