path <- fs::path("some", "simple", "path", "to", "a", "file.txt")
path_select_components(path, 1:3)
path_select_components(path, 1:3, "end")
path_select_components(path, -1, "end")
path_select_components(path, 6)
Run the code above in your browser using DataLab