我想檢查給予我的R腳本的輸出目錄是否可寫。但爲了檢查,我還需要檢查當前有效用戶所屬的組,並且我似乎無法找出如何做到這一點。該查詢也不會很好地谷歌。從內部查找用戶所屬的組R
這是我迄今爲止
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
}
我以前this來實現它。一旦我找出如何獲得有效用戶所屬的組的矢量,我就能夠自己做到這一點。
謝謝