[Rd] Suggestion: mkString(NULL) should be NA
Jeroen Ooms
jeroen.ooms at stat.ucla.edu
Thu May 12 13:20:09 CEST 2016
I would like to propose that Rf_mkString(NULL) and Rf_mkChar(NULL)
return NA rather than segfault.
Case: the mkString() and mkChar() functions are convenient to wrap
strings returned by e.g. external C libraries into an R vector.
However sometimes a library returns NULL instead of a string when the
result is unavailable. In some C libraries this can happen
unexpectedly or is even undocumented.
A good R package author always checks results for a null pointer, and
deals with it accordingly. But sometimes we make assumptions. There
was an example in the 'curl' package where a documented version string
was suddenly NULL if libcurl was built with some unusual
configuration. These problems are hard to catch and I don't see any
benefit of segfaulting for such edge cases.
Some packages use a macro like this to protect against such problems:
#define make_string(x) x ? Rf_mkString(x) : ScalarString(NA_STRING)
But I think it would make sense if this was the default behavior in
Rf_mkString and Rf_mkChar.
More information about the R-devel
mailing list