#' Delete files and directories
#'
#' @export
#' @note Updated 2022-06-08.
#'
#' @details
#' This variant hardens file path handling, for better Windows compatibility.
#'
#' @param x `character`.
#' Files or directories to be deleted.
#' Unlink base `unlink`, these must exist on disk or the function will
#' intentionally error.
#'
#' @return `integer(1)`.
#' `0` for success, `1` for failure, invisibly.
#'
#' @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)
unlink2 <- function(x) {
x <- normalizePath(
path = x,
winslash = "\\",
mustWork = TRUE
)
out <- unlink(x, recursive = TRUE)
assert(!any(file.exists(x)))
invisible(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.