file.access {base} | R Documentation

## Ascertain File Accessibility

### 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.
`mode` | integer specifying access mode required.

### Details

The `mode` value can be the exclusive or of the following values

0
  test for existence.
1
  test for execute permission.
2
  test for write permission.
4
  test for read permission.

Execute permission is ignored (always granted) under Windows, and all directories have both read and write permissions.

Please note that it is not good 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, and in recent Windows versions the underlying function in `msvcrt.dll` sometimes returns inaccurate values. It is better to wrap file open attempts in `try` instead.

### Value

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

### Note

This is intended as a replacement for the S-PLUS function `access`, a wrapper for the C function of the same name, which explains the return value encoding. Note that the return value is false for success.

### See Also

`file.info`, `try`

### Examples

    fa <- file.access(dir("."))
    table(fa) # count successes & failures

[Package base version 2.3.1 Index]