| Line 15... |
Line 15... |
| 15 |
}
|
15 |
}
|
| 16 |
\arguments{
|
16 |
\arguments{
|
| 17 |
\item{paths}{character vector of patterns for relative or absolute
|
17 |
\item{paths}{character vector of patterns for relative or absolute
|
| 18 |
filepaths. Missing values will be ignored.}
|
18 |
filepaths. Missing values will be ignored.}
|
| 19 |
\item{dirmark}{logical: should matches to directories from patterns
|
19 |
\item{dirmark}{logical: should matches to directories from patterns
|
| 20 |
that do not already end in \code{/}
|
20 |
that do not already end in \samp{/}
|
| 21 |
#ifdef windows
|
21 |
#ifdef windows
|
| 22 |
or \code{\\}
|
22 |
or \samp{\\}
|
| 23 |
#endif
|
23 |
#endif
|
| 24 |
have a slash appended? May not be supported on all platforms.}
|
24 |
have a slash appended? May not be supported on all platforms.}
|
| 25 |
}
|
25 |
}
|
| 26 |
\details{
|
26 |
\details{
|
| 27 |
This expands tilde (see \link{tilde expansion}) and wildcards in file paths.
|
27 |
This expands tilde (see \link{tilde expansion}) and wildcards in file paths.
|
| Line 30... |
Line 30... |
| 30 |
system's documentation on the \code{glob} system call. There is a
|
30 |
system's documentation on the \code{glob} system call. There is a
|
| 31 |
POSIX 1003.2 standard (see
|
31 |
POSIX 1003.2 standard (see
|
| 32 |
\url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html})
|
32 |
\url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html})
|
| 33 |
but some OSes will go beyond this.
|
33 |
but some OSes will go beyond this.
|
| 34 |
|
34 |
|
| 35 |
All systems should interpret \code{*} (match zero or more characters),
|
35 |
All systems should interpret \samp{*} (match zero or more characters),
|
| 36 |
\code{?} (match a single character) and (probably) \code{[} (begin a
|
36 |
\samp{?} (match a single character) and (probably) \samp{[} (begin a
|
| 37 |
character class or range). The handling of paths
|
37 |
character class or range). The handling of paths
|
| 38 |
ending with a separator is system-dependent. On a POSIX-2008
|
38 |
ending with a separator is system-dependent. On a POSIX-2008
|
| 39 |
compliant OS they will match directories (only), but as they are not
|
39 |
compliant OS they will match directories (only), but as they are not
|
| 40 |
valid filepaths on Windows, they match nothing there. (Earlier POSIX
|
40 |
valid filepaths on Windows, they match nothing there. (Earlier POSIX
|
| 41 |
standards allowed them to match files.)
|
41 |
standards allowed them to match files.)
|
| 42 |
% section A.4.12, https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html
|
42 |
% section A.4.12, https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html
|
| 43 |
|
43 |
|
| 44 |
The rest of these details are indicative (and based on the POSIX
|
44 |
The rest of these details are indicative (and based on the POSIX
|
| 45 |
standard).
|
45 |
standard).
|
| 46 |
|
46 |
|
| 47 |
If a filename starts with \code{.} this may need to be matched
|
47 |
If a filename starts with \samp{.} this may need to be matched
|
| 48 |
explicitly: for example \code{Sys.glob("*.RData")} may or may not
|
48 |
explicitly: for example \code{Sys.glob("*.RData")} may or may not
|
| 49 |
match \file{.RData} but will not usually match \file{.aa.RData}. Note
|
49 |
match \file{.RData} but will not usually match \file{.aa.RData}. Note
|
| 50 |
that this is platform-dependent: e.g.\sspace{}on Solaris
|
50 |
that this is platform-dependent: e.g.\sspace{}on Solaris
|
| 51 |
\code{Sys.glob("*.*")} matches \file{.} and \file{..}.
|
51 |
\code{Sys.glob("*.*")} matches \file{.} and \file{..}.
|
| 52 |
|
52 |
|
| 53 |
\code{[} begins a character class. If the first character in
|
53 |
\samp{[} begins a character class. If the first character in
|
| 54 |
\code{[...]} is not \code{!}, this is a character class which matches
|
54 |
\samp{[...]} is not \samp{!}, this is a character class which matches
|
| 55 |
a single character against any of the characters specified. The class
|
55 |
a single character against any of the characters specified. The class
|
| 56 |
cannot be empty, so \code{]} can be included provided it is first. If
|
56 |
cannot be empty, so \samp{]} can be included provided it is first. If
|
| 57 |
the first character is \code{!}, the character class matches a single
|
57 |
the first character is \samp{!}, the character class matches a single
|
| 58 |
character which is \emph{none} of the specified characters. Whether
|
58 |
character which is \emph{none} of the specified characters. Whether
|
| 59 |
\code{.} in a character class matches a leading \code{.} in the
|
59 |
\samp{.} in a character class matches a leading \samp{.} in the
|
| 60 |
filename is OS-dependent.
|
60 |
filename is OS-dependent.
|
| 61 |
|
61 |
|
| 62 |
Character classes can include ranges such as \code{[A-Z]}: include
|
62 |
Character classes can include ranges such as \samp{[A-Z]}: include
|
| 63 |
\code{-} as a character by having it first or last in a class. (The
|
63 |
\samp{-} as a character by having it first or last in a class. (The
|
| 64 |
interpretation of ranges should be locale-specific, so the example is
|
64 |
interpretation of ranges should be locale-specific, so the example is
|
| 65 |
not a good idea in an Estonian locale.)
|
65 |
not a good idea in an Estonian locale.)
|
| 66 |
|
66 |
|
| 67 |
One can remove the special meaning of \code{?}, \code{*} and
|
67 |
One can remove the special meaning of \samp{?}, \samp{*} and
|
| 68 |
\code{[} by preceding them by a backslash (except within a
|
68 |
\samp{[} by preceding them by a backslash (except within a
|
| 69 |
character class).
|
69 |
character class).
|
| 70 |
#endif
|
70 |
#endif
|
| 71 |
#ifdef windows
|
71 |
#ifdef windows
|
| 72 |
The \code{glob} system call is not part of Windows, and we supply a
|
72 |
The \code{glob} system call is not part of Windows, and we supply a
|
| 73 |
partial emulation for wildcards expansion.
|
73 |
partial emulation for wildcards expansion.
|
| 74 |
|
74 |
|
| 75 |
Wildcards are \code{*} (match zero or more characters) and \code{?} (match
|
75 |
Wildcards are \samp{*} (match zero or more characters) and \samp{?} (match
|
| 76 |
a single character). If a filename starts with \code{.} this must be
|
76 |
a single character). If a filename starts with \samp{.} this must be
|
| 77 |
matched explicitly (on Windows, but note that this is platform-dependent).
|
77 |
matched explicitly (on Windows, but note that this is platform-dependent).
|
| 78 |
|
78 |
|
| 79 |
\code{[} begins a character class. If the first character in
|
79 |
\samp{[} begins a character class. If the first character in
|
| 80 |
\code{[...]} is not \code{!}, this is a character class which matches
|
80 |
\samp{[...]} is not \samp{!}, this is a character class which matches
|
| 81 |
a single character against any of the characters specified. The class
|
81 |
a single character against any of the characters specified. The class
|
| 82 |
cannot be empty, so \code{]} can be included provided it is first. If
|
82 |
cannot be empty, so \samp{]} can be included provided it is first. If
|
| 83 |
the first character is \code{!}, the character class matches a single
|
83 |
the first character is \samp{!}, the character class matches a single
|
| 84 |
character which is \emph{none} of the specified characters. Whether
|
84 |
character which is \emph{none} of the specified characters. Whether
|
| 85 |
\code{.} in a character class matches a leading \code{.} in the
|
85 |
\samp{.} in a character class matches a leading \samp{.} in the
|
| 86 |
filename is OS-dependent.
|
86 |
filename is OS-dependent.
|
| 87 |
|
87 |
|
| 88 |
Character classes can include ranges such as \code{[A-Z]}: include
|
88 |
Character classes can include ranges such as \samp{[A-Z]}: include
|
| 89 |
\code{-} as a character by having it first or last in a class. (In
|
89 |
\samp{-} as a character by having it first or last in a class. (In
|
| 90 |
the current implementation ranges are in the numeric order of Unicode
|
90 |
the current implementation ranges are in the numeric order of Unicode
|
| 91 |
code points.)
|
91 |
code points.)
|
| 92 |
|
92 |
|
| 93 |
One can remove the special meaning of \code{?}, \code{*} and
|
93 |
One can remove the special meaning of \samp{?}, \samp{*} and
|
| 94 |
\code{[} by preceding them by a backslash (except within a
|
94 |
\samp{[} by preceding them by a backslash (except within a
|
| 95 |
character class). Note that on Windows \code{?} and \code{*} are not
|
95 |
character class). Note that on Windows \samp{?} and \samp{*} are not
|
| 96 |
valid in file names, so this is mainly for consistency with other
|
96 |
valid in file names, so this is mainly for consistency with other
|
| 97 |
platforms.
|
97 |
platforms.
|
| 98 |
|
98 |
|
| 99 |
File paths in Windows are interpreted with separator \code{\\} or
|
99 |
File paths in Windows are interpreted with separator \samp{\\} or
|
| 100 |
\code{/}. Paths with a drive but relative (such as \code{c:foo\\bar})
|
100 |
\samp{/}. Paths with a drive but relative (such as \samp{c:foo\\bar})
|
| 101 |
are tricky, but an attempt is made to handle them correctly. An
|
101 |
are tricky, but an attempt is made to handle them correctly. An
|
| 102 |
attempt is made to handle \abbr{UNC} paths starting with a double
|
102 |
attempt is made to handle \abbr{UNC} paths starting with a double
|
| 103 |
backslash. UTF-8-encoded paths not valid in the current locale can be
|
103 |
backslash. UTF-8-encoded paths not valid in the current locale can be
|
| 104 |
used.
|
104 |
used.
|
| 105 |
#endif
|
105 |
#endif
|