New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize `file_chmod`? #71

Closed
jjchern opened this Issue Feb 19, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jjchern
Copy link

jjchern commented Feb 19, 2018

Any plan on vectorizing file_chmod? Below is a comparison of file_chmod() and Sys.chmod:

library(tidyverse)
library(fs)
packageVersion("fs")
#> [1] '1.1.0.9000'

Create two test files

x <- file_create(file_temp(), "000") 
x
#> /var/folders/m8/68z5d14d7mv9qyf1bd69ych40000gn/T/RtmpOedRyI/file10e2c4e590608
file_info(x) %>% select(permissions)
#> # A tibble: 1 x 1
#>   permissions
#>   <fs::perms>
#> 1 ---------

y <- file_create(file_temp(), "444")
y
#> /var/folders/m8/68z5d14d7mv9qyf1bd69ych40000gn/T/RtmpOedRyI/file10e2c369b1f67
file_info(y) %>% select(permissions)
#> # A tibble: 1 x 1
#>   permissions
#>   <fs::perms>
#> 1 r--r--r--

Sys.chmod() can set permissions of one or more files

Sys.chmod(c(x, y), "777", use_umask = FALSE)
file_info(x) %>% select(permissions)
#> # A tibble: 1 x 1
#>   permissions
#>   <fs::perms>
#> 1 rwxrwxrwx
file_info(y) %>% select(permissions)
#> # A tibble: 1 x 1
#>   permissions
#>   <fs::perms>
#> 1 rwxrwxrwx

file_chmod() can't handle more than one file

file_chmod(c(x, y), "666")
#> Error in FUN(X[[i]], ...): Expecting a single value: [extent=2].

If it's an intended feature, perhaps it'd help to add an example for handling multiple files? Something like

x <- file_create(file_temp(), "000") 
y <- file_create(file_temp(), "444")
lapply(c(x, y), file_chmod, mode = "777")
file_info(x)$permissions
file_info(y)$permissions

@jimhester jimhester closed this in 52c5788 Feb 19, 2018

@jimhester

This comment has been minimized.

Copy link
Member

jimhester commented Feb 19, 2018

Thanks, file_chmod() should now be vectorized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment