R: Ascertain File Accessibility (original) (raw)

file.access {base} R Documentation

Description

Utility function to access information about files on the user's file systems.

Usage

file.access(names, mode = 0)

Arguments

names character vector containing file names. Tilde-expansion will be done: see path.expand.
mode integer specifying access mode required: see ‘Details’.

Details

The mode value can be the exclusive or (xor), i.e., a partial sum of the following values, and hence must be in 0:7,

0

test for existence.

1

test for execute permission.

2

test for write permission.

4

test for read permission.

Permission will be computed for real user ID and real group ID (rather than the effective IDs).

Please note that it is not a good idea to use this function to test before trying to open a file. On a multi-tasking system, it is possible that the accessibility of a file will change between the time you call file.access() and the time you try to open the file. It is better to wrap file open attempts in [try](../../base/help/try.html).

Value

An integer vector with values 0 for success and -1 for failure.

Note

This was written as a replacement for the S-PLUS functionaccess, a wrapper for the C function of the same name, which explains the return value encoding. Note that the return value isfalse for success.

See Also

[file.info](../../base/help/file.info.html) for more details on permissions,[Sys.chmod](../../base/help/Sys.chmod.html) to change permissions, and[try](../../base/help/try.html) for a ‘test it and see’ approach.

[file_test](../../utils/html/filetest.html) for shell-style file tests.

Examples

fa <- file.access(dir("."))

table(fa) # count successes & failures


[Package _base_ version 4.6.0 Index]