All functions apart from path_real() are purely path computations, so the files in question do not need to exist on the filesystem.




path_abs(path, start = ".")


path_rel(path, start = ".")


path_has_parent(path, parent)



A character vector of one or more paths.


A character vector or a list of character vectors, corresponding to split paths.


A starting directory to compute the path relative to.


The parent path.


The new path(s) in an fs_path object, which is a character vector that also has class fs_path. Except path_split(), which returns a list of character vectors of path components.


  • path_real: returns the canonical path, eliminating any symbolic links and the special references ~, ~user, ., and .., , i.e. it calls path_expand() (literally) and path_norm() (effectively).

  • path_split: splits paths into parts.

  • path_join: joins parts together. The inverse of path_split(). See path() to concatenate vectorized strings into a path.

  • path_abs: returns a normalized, absolute version of a path.

  • path_norm: eliminates . references and rationalizes up-level .. references, so A/./B and A/foo/../B both become A/B, but ../B is not changed. If one of the paths is a symbolic link, this may change the meaning of the path, so consider using path_real() instead.

  • path_rel: computes the path relative to the start path, which can be either an absolute or relative path.

  • path_common: finds the common parts of two (or more) paths.

  • path_has_parent: determine if a path has a given parent.

See also

path_expand() for expansion of user's home directory.


.old_wd <- setwd(tempdir()) dir_create("a") file_create("a/b") link_create(path_abs("a"), "c") # Realize the path path_real("c/b")
#> /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpOSQGgR/a/b
# Split a path parts <- path_split("a/b") parts
#> [[1]] #> [1] "a" "b" #>
# Join it together path_join(parts)
#> a/b
# Find the absolute path path_abs("..")
#> /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T
# Normalize a path path_norm("a/../b\\c/.")
#> b/c
# Compute a relative path path_rel("/foo/abc", "/foo/bar/baz")
#> ../../abc
# Find the common path between multiple paths path_common(c("/foo/bar/baz", "/foo/bar/abc", "/foo/xyz/123"))
#> /foo
# Cleanup dir_delete("a") link_delete("c") setwd(.old_wd)