file_test
Shell-style Tests on Files

Description

Tests files or directories in a shell-style.

Usage

file_test(op, x, y)

Arguments

op a character string specifying the operation of test style on files.
The supported unary tests are:
"-f" tests the existence of x and if it is a file.fs.
"-d" tests the existence of x and if it is a directory.
"-x" tests the execute permission of x.
The supported binary tests are:
"-nt" tests the existence of x and y, and if the modified time of x is newer than the one of y.
"-ot" tests the existence of x and y, and if the modified time of x is older than the one of y.
x a character string specifying the file or directory path. Required.
y a character string specifying the second file or directory path. Required for binary tests only.

Details

This utility function is implemented for shell-style tests on files or directories. Unsupported tests cause the function to stop with an error message.
Value
returns a logical value. If TRUE, the test is successful. Otherwise, returns FALSE.
See Also
file.access, file.info
Examples
file_test("-f", .libPaths()[1])  # FALSE
file_test("-f", file.path(.libPaths()[1], "stats", "DESCRIPTION")) # TRUE
file_test("-d", .libPaths()[1])  # TRUE
file_test("-x", .libPaths()[1])  # TRUE

# Test if the modified time of package "utils" is older than "stats" file_test("-ot", file.path(.libPaths()[1], "utils"), file.path(.libPaths()[1], "stats"))

# Unsupported test causes a stop with message "test 'foo' is not available" file_test("foo", .libPaths()[1])

Package utils version 6.1.1-7
Package Index