I want to check if the output directory given to my R script is writable. But to check that, I also need to check the groups the current effective user belongs to, and I do not seem to be able to find out how to do that. The query does not google well either.
This is what I have so far
is.writable <- function(dir)
{
if(file.info(outputDir)['size'] == NA || file.info(outputDir)['isdir'] == FALSE)
return FALSE
mode <- file.info['mode']
owner <- file.info['uname']
fileGroup <- file.info['grname']
user <- Sys.info()[["effective_user"]]
if(bitwAnd(mode,2) != 0) # every can access
return TRUE
#if(bitwAnd(mode,16) != 0) # 16=0020 in octal, some group has access
if(bitwAnd(mode,128) != 0) # 128 = 0200 in octal, the owner has write access
return user == owner
}
I used this to implement it. I would be able to do it on my own once I figure out how to get a vector of the groups the effective user belongs to.
Thank you,