match.path(path, table, nomatch=NA, as.path=T)
table
.
path
.
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).
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
).
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
.
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.
# "." 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)]