| Sys.glob | R Documentation |
Function to do wildcard expansion (also known as ‘globbing’) onfile paths.
Sys.glob(paths, dirmark = FALSE)
paths | character vector of patterns for relative or absolutefilepaths. Missing values will be ignored. |
dirmark | logical: should matches to directories from patternsthat do not already end in |
This expands tilde (see tilde expansion) and wildcards in file paths. For precise details of wildcards expansion, see yoursystem's documentation on theglob system call. There is aPOSIX 1003.2 standard (seehttps://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html)but some OSes will go beyond this.
All systems should interpret* (match zero or more characters),? (match a single character) and (probably)[ (begin acharacter class or range). The handling of pathsending with a separator is system-dependent. On a POSIX-2008compliant OS they will match directories (only), but as they are notvalid filepaths on Windows, they match nothing there. (Earlier POSIXstandards allowed them to match files.)
The rest of these details are indicative (and based on the POSIXstandard).
If a filename starts with. this may need to be matchedexplicitly: for exampleSys.glob("*.RData") may or may notmatch ‘.RData’ but will not usually match ‘.aa.RData’. Notethat this is platform-dependent: e.g. on SolarisSys.glob("*.*") matches ‘.’ and ‘..’.
[ begins a character class. If the first character in[...] is not!, this is a character class which matchesa single character against any of the characters specified. The classcannot be empty, so] can be included provided it is first. Ifthe first character is!, the character class matches a singlecharacter which isnone of the specified characters. Whether. in a character class matches a leading. in thefilename is OS-dependent.
Character classes can include ranges such as[A-Z]: include- as a character by having it first or last in a class. (Theinterpretation of ranges should be locale-specific, so the example isnot a good idea in an Estonian locale.)
One can remove the special meaning of?,* and[ by preceding them by a backslash (except within acharacter class).
A character vector of matched file paths. The order issystem-specific (but in the order of the elements ofpaths): itis normally collated in either the current locale or in byte (ASCII)order; however, on Windows collation is in the order of Unicodepoints.
Directory errors are normally ignored, so the matches are toaccessible file paths (but not necessarily accessible files).
path.expand.
Quotes for handling backslashes in character strings.
Sys.glob(file.path(R.home(), "library", "*", "R", "*.rdx"))
Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.