Match Paths or Strings

DESCRIPTION:

Determines whether two character strings refer to the same file system entity, or (optionally) match exactly.

USAGE:

match.path(path, table, nomatch=NA, as.path=T) 

REQUIRED ARGUMENTS:

path
character vector of (what are by default) paths that are to be looked for in table.
table
character vector of (what are by default) paths that are possible matches of path.

OPTIONAL ARGUMENTS:

nomatch
the value to be returned when an item in path does not match any item in table. A useful alternative to NA is nomatch=0, which has the effect that unmatched items are ignored when the matched indices are used in subscripts (see the last example below).
as.path
logical vector, cyclically repeated to the length of table, specifying whether the corresponding element of table should be considered to match path if they refer to the same file system entity (see examples below). If F, match.path has the same functionality as match for character data, but is slower. This allows table to be a mixture of path and non-path names (as might be returned by search).

VALUE:

integer vector the same length as path giving, for each element of path, the smallest i such that table[i] matches (as defined by as.path) that element. If no value in table matches path[j], then the jth element of the result is nomatch.

DETAILS:

If (for any possible match in which as.path is T) either path or table contains a drive designation (e.g., "x:") that refers to a remote machine, match.path will query the operating system for the remote machine name corresponding to that drive and thus may experience a slight delay.

SEE ALSO:

, , , , ,

EXAMPLES:

# "." and dos("cd") both refer to current working directory,  
# but 'match' fails (returning NA) while 'match.path'  
# succeeds (returning 1) 
match(".\\mydir\\myfile", paste(dos("cd"),"mydir","myfile",sep="\\")) 
match.path(".\\mydir\\myfile", paste(dos("cd"),"mydir","myfile",sep="\\")) 
# determines which of "//remote1/c", "//remote2/c" or "//remote3/c" that  
# "r:" is mapped to 
remote.names <- paste("//remote",1:3,"/c",sep="") 
remote.names[match.path("r:\\",remote.names,0)]