Skip to content

Instantly share code, notes, and snippets.

@xvrdm
Last active January 28, 2019 10:10
Show Gist options
  • Save xvrdm/842a185ac800626f349480a9a781d7e8 to your computer and use it in GitHub Desktop.
Save xvrdm/842a185ac800626f349480a9a781d7e8 to your computer and use it in GitHub Desktop.
Comparaison Table: fs / base / shell

dir_

fs base shell
dir_ls("/path") list.files("/path") ls /path
dir_info("/path") do.call(rbind, lapply(list.files("/path"), file.info)) ls -al /path
dir_copy("/path", "/new-path") dir.create("/new-path"); file.copy("/path", "/new-path", recursive=TRUE) cp /path /new-path
dir_create("/path") dir.create("/path") mkdir /path
dir_delete("/path") unlink("/path", recursive = TRUE) rm -rf /path
dir_exists("/path") dir.exists("/path") if [ -d "/path" ]; then ... ; fi
dir_move()... (Nope, see file_move!) file.rename("/path", "/new-path") mv /path /new-path

file_

fs base shell
file_chmod("/path", "mode") No easy way chmod mode /path
file_chown("path", "user_id", "group_id") No easy way chown options /path
file_copy("/path", "/new-path") file.copy("/path", "/new-path") cp /path /new-path
file_create("/new-path") file.create("/new-path") touch /new-path
file_delete("/path") unlink("/path") rm /path
file_exists("/path") file.exists("/path") if [ -f "/path" ]; then ... ; fi
file_info("/path") file.info("/path") ls -al /path
file_move("/path", "/new-path") file.rename("/path", "/new-path") mv /path /new-path
file_show("/path") browseURL("path") open /path
file_temp TODO TODO
file_touch() (doesn't create file) TODO TODO

path_

fs base shell
path("top_dir", "nested_dir", "file", ext = "ext") file.path("top_dir", "nested_dir", "file.ext") top_dir/nested_dir/file.ext
path_expand("~/path") path.expand() Need scripting.
path_dir("/path") dirname("/path") dirname /path
path_file("/path") basename("/path") basename /path
path_home() path.expand("~") $HOME
path_ext_remove("/path") sub("\\.[a-zA-Z0-9]*$", "", "/path") Need scripting.
path_ext_set("/path", "new_ext") sub("\\.[a-zA-Z0-9]*$", "new_ext", "/path") Need scripting.
@cderv
Copy link

cderv commented Jan 21, 2019

As discussed, I think there is some difference on windows and Linux / MAC. Maybe this should be taken into account.
I know this one :

fs::path_home()
#> C:/Users/chris
fs::path_expand("~")
#> C:/Users/chris
path.expand("~")
#> [1] "C:/Users/chris/Documents"
fs::path_expand_r("~")
#> C:/Users/chris/Documents
fs::path_home_r()
#> C:/Users/chris/Documents

Created on 2019-01-21 by the reprex package (v0.2.1)

I'll be happy to test on windows the table.

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