chmod o+r:
mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod|4)
chmod o-r:
mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod&!as.octmode(4))
Question
How can I use the Sys.chmod
function in R to toggle readability by "other", i.e. the equivalent of:
chmod o+r myfile
chmod o-r myfile
I specifically want to leave the other parts of the mode alone.
Solution
chmod o+r:
mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod|4)
chmod o-r:
mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod&!as.octmode(4))