names
have the access modes
specified by
mode
, for example, whether the files exist or are writable.
access(names, mode=0) file.access(names, mode=0)
names
vector, it is repeated cyclically. The values
for the elements of
mode
are as follows:
mode
is a vector of 0s and 2s.)
access
returns a numeric vector of length
length(names)
consisting of 0s (if the file
has the specified access) and -1s (if the file does not).
The value of
file.access
is a named vector: the result
of calling
access
then using the value of the
names
argument as the vector's
names
attribute.
The
access
function is an implementation of the C library function access.
The
file.access
function emulates R's function
of the same name.
access("trytoed.it", 2) # a return value of -1 indicates the file is not writable (it may or # may not exist) access("trytoed.it", 0) # a subsequent return value of 0 indicates that the file exists # (implying the file is read-only)
# check access mode of two files (one does not exist) tfile1 <- tempfile("a") tfile2 <- tempfile("b") cat("Today's date is:",date(),"\n", file=tfile1) file.access(c(tfile1,tfile2),mode=4) unlink(tfile1)