fileAccess
From R.utils v1.7.0
by Henrik Bengtsson
Checks the permission of a file or a directory
Checks the permission of a file or a directory.
- Keywords
- programming, IO
Usage
## S3 method for class 'default':
fileAccess(pathname, mode=0, safe=TRUE, ...)
Arguments
- pathname
- A
character
string of the file or the directory to be checked. - mode
- An
integer
(0,1,2,4), cf.file.access
(). - safe
- If
TRUE
, the permissions are tested more carefully, otherwisefile.access
() is used. - ...
- Not used.
Details
In Rthere 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].
Value
- Returns an
integer
; 0 if the permission exists, -1 if not.
References
[1] R-devel thread
file.access() on network (mounted) drive on Windows Vista?
on Nov 26, 2008.
[2] Filesystem permissions, Wikipedia, 2010.
See Also
Examples
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Current directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- "."
# Test for existence
print(fileAccess(path, mode=0))
# Test for execute permission
print(fileAccess(path, mode=1))
# Test for write permission
print(fileAccess(path, mode=2))
# Test for read permission
print(fileAccess(path, mode=4))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A temporary file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- tempfile()
cat(file=pathname, "Hello world!")
# Test for existence
print(fileAccess(pathname, mode=0))
# Test for execute permission
print(fileAccess(pathname, mode=1))
# Test for write permission
print(fileAccess(pathname, mode=2))
# Test for read permission
print(fileAccess(pathname, mode=4))
file.remove(pathname)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The 'base' package directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- system.file(package="base")
# Test for existence
print(fileAccess(path, mode=0))
# Test for execute permission
print(fileAccess(path, mode=1))
# Test for write permission
print(fileAccess(path, mode=2))
# Test for read permission
print(fileAccess(path, mode=4))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The 'base' package DESCRIPTION file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pathname <- system.file("DESCRIPTION", package="base")
# Test for existence
print(fileAccess(pathname, mode=0))
# Test for execute permission
print(fileAccess(pathname, mode=1))
# Test for write permission
print(fileAccess(pathname, mode=2))
# Test for read permission
print(fileAccess(pathname, mode=4))
Community examples
Looks like there are no examples yet.