Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking file permissions from R

Dear Stackoverflowers,

I am looking for a way to check the file permissions in the current folder (the one that can be obtained using getwd()) in the R language. I am working on a Unix platform and know that I can get file permission mode using file.info(), but I do not know how to check to which category (owner / group / rest) I belong and thus what specific rights I have.

A second question that I have is whether this can also be done cross-platform, so that this would work also on other platforms (most importantly on Windows).

Thank you very much for you help!

Thomas

like image 766
dertomtom Avatar asked Aug 31 '25 16:08

dertomtom


1 Answers

file.access() returns this information. So

file.access(".", 2)

tells you whether or not you can write to the current working directory. You can supply a vector of filenames/directories as appropriate.

Note that if there is a chance that permissions can change underneath you (i.e. multitasking system), you may be better off to just use try and catch the error if you don't have permissions.

like image 131
Scott C Wilson Avatar answered Sep 02 '25 14:09

Scott C Wilson