From jonathan-rbugs at swintons.net  Wed Jan 21 17:36:40 2004
From: jonathan-rbugs at swintons.net (jonathan-rbugs@swintons.net)
Date: Wed Jan 21 17:37:01 2004
Subject: [Rd] [g]sub behaviour with NA (PR#6451)
Message-ID: <20040121163640.0583510516@slim.kubism.ku.dk>

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.


[Rd] [g]sub behaviour with NA (PR#6451)
jonathan-rbugs@swintons.net