rappdirs
rappdirs copied to clipboard
Path separator consistency on Windows
For now it is just an observation and it does not cause issue directly. However, it seems not quite right to have different path separator in the same PATH.
On windows, the path separator is not consistent when path are built - see below
# \\ at the beggining, / at the end.
rappdirs::user_cache_dir("dummy", version = "1.1.0")
#> [1] "C:\\Users\\chris\\AppData\\Local/dummy/dummy/1.1.0/Cache"
# this is because this does not use .Platform$file.sep
rappdirs:::win_path("local")
#> [1] "C:\\Users\\chris\\AppData\\Local"
# but is used as based with file_path using the sep
rappdirs:::file_path("a", "b")
#> [1] "a/b"
dir <- rappdirs:::file_path(rappdirs:::win_path("local"), "dummy", "1.1.0")
dir
#> [1] "C:\\Users\\chris\\AppData\\Local/dummy/1.1.0"
# Path needs to be normalize to be consistent
fs::path_norm(dir)
#> C:/Users/chris/AppData/Local/dummy/1.1.0
# But R 4.0+ does the same so maybe it is expected ?
tools::R_user_dir("dummy", "cache")
#> [1] "C:\\Users\\chris\\AppData\\Local/R/cache/R/dummy"
Created on 2021-07-07 by the reprex package (v2.0.0)
Is the good practice to normalize the path built anyway ?
Yes, I think we could probably be more explicit about path separators on Windows.