Skip to content

fwrite does not follow system-level umask #2049

@gnguy

Description

@gnguy

It appears that when using fwrite to write files, it does not follow the system-level umask settings. My global umask settings have been set to 002, so I expect that R should write files with rw-rw-r-- permissions.

When writing files using fwrite, they appear to write files with rw-r--r-- permissions, which I would associate with a umask of 022. When I write files immediately after that while using write.csv, they write appropriately with rw-rw-r-- permissions.

library(data.table)
Sys.umask()

2

Sys.umask("002") # Not needed, but just to make sure
filename <- "~/Desktop/umask_test.csv"

system(paste0("rm ", filename))
test_df <- data.frame(x=c(0,1))
fwrite(test_df, filename)
system(paste0("ls -la ",filename))

-rw-r--r-- 1 myuser 50513 6 Mar 1 15:34 /Users/myuser/Desktop/umask_test.csv

system(paste0("rm ", filename))
write.csv(test_df, filename)
system(paste0("ls -la ", filename))

-rw-rw-r-- 1 myuser 50513 19 Mar 1 15:34 /Users/myuser/Desktop/umask_test.csv

sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] data.table_1.10.4

loaded via a namespace (and not attached):
[1] tools_3.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions