I'm on Linux and want to share R
output with co-workers while also allowing them to overwrite my files. However, when I write a file the permissions are set to read-only for the group, for example:
> write.csv(data.frame(a = 1:3), file = "/tmp/test.csv")
> file.mode("/tmp/test.csv")
[1] "644"
creates a file that is only writeable by myself. Is there some option I can set so that the files I write have permission 660
set automatically for all ways of writing files (write.csv
, data.table
, etc)?
The solution is to set the umask
using Sys.umask
as follows.
# Before setting umask as in the question:
> write.csv(data.frame(a = 1:3), file = "/tmp/test.csv")
> file.mode("/tmp/test.csv")
[1] "644"
# Setting the umask results in succes:
Sys.umask("006")
> write.csv(data.frame(a = 1:3), file = "/tmp/test2.csv")
> file.mode("/tmp/test2.csv")
[1] "660"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With