From jeroen.ooms at stat.ucla.edu  Tue May 24 18:30:18 2016
From: jeroen.ooms at stat.ucla.edu (Jeroen Ooms)
Date: Tue, 24 May 2016 18:30:18 +0200
Subject: [Rd] Suggestion: mkString(NULL) should be NA
In-Reply-To: <CADwqtCP2O7zUSJ3BHvYbkD25EyJPyj9LhdazJf5UzELVW1_9-w@mail.gmail.com>
References: <CABFfbXt7raZDRaGP+T=XWKeBZq8oh88FRh8+Xj7jFkf_VFspsA@mail.gmail.com>
	<CABFfbXu0LTrSy9Qq5mouq6fX=nN=NF9xshtM8Q9khYn3cWtEQw@mail.gmail.com>
	<CADwqtCP2O7zUSJ3BHvYbkD25EyJPyj9LhdazJf5UzELVW1_9-w@mail.gmail.com>
Message-ID: <CABFfbXtUHYepH93PZrYktNbFfNX-Y8iF5Pk6DYOgUFk=MGK7pA@mail.gmail.com>

On Tue, May 24, 2016 at 5:59 PM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
> Shouldn't Rf_mkString(NULL) return (the c-level equivalent of) character()
> rather than the NA_character_?

No. It should still be safe to assume that mkString() always returns a
character vector of exactly length one. Anything else could lead to
type errors.

> An empty string and NULL aren't the same.

Exactly! So if you pass in an empty C string, you get an empty R
string, and if you pass in a null pointer you get NA.

Rf_mkString(NULL)   <--> NA
Rf_mkString("")   <--> ""

There is no ambiguity, and much better than segfaulting.



[Rd] Suggestion: mkString(NULL) should be NA
Jeroen Ooms