Learn R Programming

fs (version 1.0.0)

create: Create files, directories, or links

Description

These functions ensure that path exists; if it already exists it will be left unchanged. That means that compared to file.create(), file_create() will not truncate an existing file, and compared to dir.create(), dir_create() will silently ignore existing directories.

Usage

file_create(path, mode = "u=rw,go=r")

dir_create(path, mode = "u=rwx,go=rx", recursive = TRUE)

link_create(path, new_path, symbolic = TRUE)

Arguments

path

A character vector of one or more paths.

mode

If file/directory is created, what mode should it have?

Links do not have mode; they inherit the mode of the file they link to.

recursive

should intermediate directories be created if they do not exist?

new_path

The path where the link should be created.

symbolic

Boolean value determining if the link should be a symbolic (the default) or hard link.

Value

The path to the created object (invisibly).

Examples

Run this code
# NOT RUN {
x <- file_create(file_temp())
is_file(x)
# dir_create applied to the same path will fail
try(dir_create(x))

x <- dir_create(file_temp())
is_dir(x)
# file_create applied to the same path will fail
try(file_create(x))
# }

Run the code above in your browser using DataLab