[Rd] [g]sub behaviour with NA (PR#6451)

jonathan-rbugs at swintons.net jonathan-rbugs at swintons.net
Wed Jan 21 17:36:40 MET 2004


Full_Name: Jonathan Swinton
Version: 1.9.0
OS: Windows 2000
Submission from: (NULL) (193.132.159.34)


Attempting to substitute a NA causes an error in sub.

> sub(x=NA,pattern="x",replacement="y")
Error in sub(pattern, replacement, x, ignore.case, extended) : 
	invalid argument
> sub(x=NA,pattern=NA,replacement="y")
[1] NA

The help page for sub says only
   For 'regexpr' it is an error for 'pattern' to be 'NA', otherwise
     'NA' is permitted and matches only itself.
so that this behaviour is undocumented. 

I believe that sub(x=NA,pattern,replacement) should always be NA.



More information about the R-devel mailing list