fileAccess.RdChecks the permission of a file or a directory.
# S3 method for default
fileAccess(pathname, mode=0, safe=TRUE, ...)A character string of the file or the directory
to be checked.
An integer (0,1,2,4), cf. file.access().
If TRUE, the permissions are tested more carefully,
otherwise file.access() is used.
Not used.
Returns an integer; 0 if the permission exists, -1 if not.
In R there is file.access() for checking whether the
permission of a file.
Unfortunately, that function cannot be 100% trusted depending on
platform used and file system queried, cf. [1].
This function follows symbolic links (also on Windows) and returns a value based on the link target (rather than the link itself).
[1] R-devel thread
file.access() on network (mounted) drive on Windows Vista?
on Nov 26, 2008.
https://stat.ethz.ch/pipermail/r-devel/2008-December/051461.html
[2] Filesystem permissions, Wikipedia, 2010.
https://en.wikipedia.org/wiki/Filesystem_permissions
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Current directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- "."
# Test for existence
print(fileAccess(path, mode=0))
#> [1] 0
# Test for execute permission
print(fileAccess(path, mode=1))
#> [1] 0
# Test for write permission
print(fileAccess(path, mode=2))
#> [1] 0
# Test for read permission
print(fileAccess(path, mode=4))
#> [1] 0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A temporary file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- tempfile()
cat(file=pathname, "Hello world!")
# Test for existence
print(fileAccess(pathname, mode=0))
#> [1] 0
# Test for execute permission
print(fileAccess(pathname, mode=1))
#> [1] -1
# Test for write permission
print(fileAccess(pathname, mode=2))
#> [1] 0
# Test for read permission
print(fileAccess(pathname, mode=4))
#> [1] 0
file.remove(pathname)
#> [1] TRUE
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The 'base' package directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- system.file(package="base")
# Test for existence
print(fileAccess(path, mode=0))
#> [1] 0
# Test for execute permission
print(fileAccess(path, mode=1))
#> [1] 0
# Test for write permission
print(fileAccess(path, mode=2))
#> [1] -1
# Test for read permission
print(fileAccess(path, mode=4))
#> [1] 0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The 'base' package DESCRIPTION file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- system.file("DESCRIPTION", package="base")
# Test for existence
print(fileAccess(pathname, mode=0))
#> [1] 0
# Test for execute permission
print(fileAccess(pathname, mode=1))
#> [1] -1
# Test for write permission
print(fileAccess(pathname, mode=2))
#> [1] -1
# Test for read permission
print(fileAccess(pathname, mode=4))
#> [1] 0