Debian Codegraph @

man/path_math.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/path.R
3 \name{path_math}
4 \alias{path_math}
5 \alias{path_real}
6 \alias{path_split}
7 \alias{path_join}
8 \alias{path_abs}
9 \alias{path_norm}
10 \alias{path_rel}
11 \alias{path_common}
12 \alias{path_has_parent}
13 \title{Path computations}
14 \usage{
15 path_real(path)
16
17 path_split(path)
18
19 path_join(parts)
20
21 path_abs(path, start = ".")
22
23 path_norm(path)
24
25 path_rel(path, start = ".")
26
27 path_common(path)
28
29 path_has_parent(path, parent)
30 }
31 \arguments{
32 \item{path}{A character vector of one or more paths.}
33
34 \item{parts}{A character vector or a list of character vectors, corresponding
35 to split paths.}
36
37 \item{start}{A starting directory to compute the path relative to.}
38
39 \item{parent}{The parent path.}
40 }
41 \value{
42 The new path(s) in an \code{fs_path} object, which is a character vector
43 that also has class \code{fs_path}. Except \code{path_split()}, which returns a list
44 of character vectors of path components.
45 }
46 \description{
47 All functions apart from \code{path_real()} are purely path computations, so the
48 files in question do not need to exist on the filesystem.
49 }
50 \section{Functions}{
51 \itemize{
52 \item \code{path_real()}: returns the canonical path, eliminating any symbolic
53 links and the special references \code{~}, \code{~user}, \code{.}, and \code{..}, , i.e. it
54 calls \code{path_expand()} (literally) and \code{path_norm()} (effectively).
55
56 \item \code{path_split()}: splits paths into parts.
57
58 \item \code{path_join()}: joins parts together. The inverse of \code{\link[=path_split]{path_split()}}.
59 See \code{\link[=path]{path()}} to concatenate vectorized strings into a path.
60
61 \item \code{path_abs()}: returns a normalized, absolute version of a path.
62
63 \item \code{path_norm()}: eliminates \code{.} references and rationalizes up-level
64 \code{..} references, so \code{A/./B} and \code{A/foo/../B} both become \code{A/B}, but \code{../B}
65 is not changed. If one of the paths is a symbolic link, this may change the
66 meaning of the path, so consider using \code{path_real()} instead.
67
68 \item \code{path_rel()}: computes the path relative to the \code{start} path,
69 which can be either an absolute or relative path.
70
71 \item \code{path_common()}: finds the common parts of two (or more) paths.
72
73 \item \code{path_has_parent()}: determine if a path has a given parent.
74
75 }}
76 \examples{
77 \dontshow{.old_wd <- setwd(tempdir())}
78 dir_create("a")
79 file_create("a/b")
80 link_create(path_abs("a"), "c")
81
82 # Realize the path
83 path_real("c/b")
84
85 # Split a path
86 parts <- path_split("a/b")
87 parts
88
89 # Join it together
90 path_join(parts)
91
92 # Find the absolute path
93 path_abs("..")
94
95 # Normalize a path
96 path_norm("a/../b\\\\c/.")
97
98 # Compute a relative path
99 path_rel("/foo/abc", "/foo/bar/baz")
100
101 # Find the common path between multiple paths
102 path_common(c("/foo/bar/baz", "/foo/bar/abc", "/foo/xyz/123"))
103
104 # Cleanup
105 dir_delete("a")
106 link_delete("c")
107 \dontshow{setwd(.old_wd)}
108 }
109 \seealso{
110 \code{\link[=path_expand]{path_expand()}} for expansion of user's home directory.
111 }