Skip to contents

Validates that every path of a character value can be written: an existing file or directory must be writable, and a path that does not exist yet needs a writable parent directory. Use it for output files and directories.

Usage

require_writable(restriction)

Arguments

restriction

a restriction object.

Value

The modified restriction object.

Details

Writability is judged by file.access(). On Windows it reflects the read-only attribute and not access control lists, so a directory that is denied by permissions can still pass. The check cannot tell whether the disk has room.

Examples

out_dir <- restrict("out") |> require_writable()
out_dir(tempdir())
out_dir(file.path(tempdir(), "result.csv"))