[R] misbehavior with extract_numeric() from tidyr
Hadley Wickham
h.wickham at gmail.com
Mon Apr 20 21:10:44 CEST 2015
On Mon, Apr 20, 2015 at 1:57 PM, arnaud gaboury
<arnaud.gaboury at gmail.com> wrote:
> On Mon, Apr 20, 2015 at 6:09 PM, William Dunlap <wdunlap at tibco.com> wrote:
>
>> The hyphen without a following digit confuses tidyr::extract_numeric().
>> E.g.,
>> > extract_numeric("23 ft-lbs")
>> Warning message:
>> In extract_numeric("23 ft-lbs") : NAs introduced by coercion
>> [1] NA
>> > extract_numeric("23 ft*lbs")
>> [1] 23
>>
>
> See[0] for the reason on the minus in the regex. It is not a bug but a wish.
> I am honestly very surprised the maintainer decided to go with such a so
> simple solution for negative numbers.
>
> [0]https://github.com/hadley/tidyr/issues/20
Any heuristic is going to fail in some circumstances. If you want to
be sure it's doing what you want for your use case, write the regular
expression yourself.
Hadley
--
http://had.co.nz/
More information about the R-help
mailing list