[Rd] [PATCH] file.access returns success for NA

Scott Kostyshak skostysh at princeton.edu
Fri Oct 4 01:56:33 CEST 2013


Currently on R I get the following:

> file.access(c("doesNotExist", NA))
doesNotExist <NA>
  -1    0

where 0 means success. Is the 0 correct? I was expecting either NA or -1.

?file.access does not mention how NA values should be handled. The
subsection "3.3.4 NA handling" from the R Language Definition manual
suggest to me that file.access should return NA if given NA. I
interpret it in this way because if an element in the input vector is
NA, that means that there is a filename that exists but is not known.
Thus, I thought that file.access should return NA because it is not
known whether the file corresponding to the missing filename exists.

Perhaps file.access acts in this way to maintain compatibility with
the S-PLUS function ‘access’ (which I currently do not have a way of
testing to see how it handles NAs) ? If this is the case, would a
patch for ?file.access be considered?

Below is a patch that changes the return of an NA to NA.

Index: trunk/src/main/platform.c
===================================================================
--- trunk/src/main/platform.c (revision 64011)
+++ trunk/src/main/platform.c (working copy)
@@ -1299,7 +1299,7 @@
  access(R_ExpandFileName(translateChar(STRING_ELT(fn, i))),
        modemask);
 #endif
- } else INTEGER(ans)[i] = FALSE;
+ } else INTEGER(ans)[i] = NA_INTEGER;
     UNPROTECT(1);
     return ans;
 }

Comments?

Scott

> sessionInfo()
R Under development (unstable) (2013-09-27 r64011)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
>


--
Scott Kostyshak
Economics PhD Candidate
Princeton University



More information about the R-devel mailing list