Re: [R] strange behavior in base::as.double

2024-05-01 Thread Ivan Krylov via R-help
В Wed, 1 May 2024 11:32:32 -0400
Carl Witthoft  пишет:

> but as.double('123e') returns 123 -- or whatever the first digit is.

Nicely spotted problem!

Prof. Brian D. Ripley has fixed it in R-devel revision 86436 [*]. Now
as.double('123e') will also return NA. I think that the fix will become
part of R-4.4.1 when it's released.

-- 
Best regards,
Ivan

[*]
https://github.com/r-devel/r-svn/commit/9069a729f5bf69de8250a4c91dd482fcf64e1154

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange behavior in base::as.double

2024-05-01 Thread Duncan Murdoch

On 01/05/2024 11:32 a.m., Carl Witthoft wrote:

Hello.
I'm running R 4.4.0 on an iMac Venture 13.5.2 .   There appears to be a bug
in as.double().

Create a string with a numeric digits followed by a single letter a thru f
(as tho' it's base 16).

for  K  in (a,b,c,d, and f ) ,  as.double( '123K') returns NA
but as.double('123e') returns 123 -- or whatever the first digit is.

Please let me know if there are additional tests I can try .


This has been mentioned in the news recently.  123e was taken as 
scientific format, with an implied 0 at the end, i.e. 123e0.  That is no 
longer true after the recent fix; I'm not sure if it is in R 
4.4.0-patched yet.


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange behavior in base::as.double

2024-05-01 Thread Iris Simmons
This happens because "123e" looks like exponential form. This string has no
exponent, so it gets treated as 0 exponent.

If you're interested in converting hex numbers, append 0x:

as.numeric("0x123a")

or use strtoi:

strtoi("123a", 16)

On Wed, May 1, 2024, 15:24 Carl Witthoft  wrote:

> Hello.
> I'm running R 4.4.0 on an iMac Venture 13.5.2 .   There appears to be a bug
> in as.double().
>
> Create a string with a numeric digits followed by a single letter a thru f
> (as tho' it's base 16).
>
> for  K  in (a,b,c,d, and f ) ,  as.double( '123K') returns NA
> but as.double('123e') returns 123 -- or whatever the first digit is.
>
> Please let me know if there are additional tests I can try .
>
>
> thanks
> Carl Witthoft
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange behavior in base::as.double

2024-05-01 Thread Sarah Goslee
Hi Carl,

Not that strange: R thinks you're using scientific notation. Also not a Mac bug.

> as.double('123e')
[1] 123
> as.double('123e+0')
[1] 123
> as.double('123e+1')
[1] 1230
> as.double('123e-1')
[1] 12.3

Can you explain what you're trying to accomplish?

Sarah

On Wed, May 1, 2024 at 3:24 PM Carl Witthoft  wrote:
>
> Hello.
> I'm running R 4.4.0 on an iMac Venture 13.5.2 .   There appears to be a bug
> in as.double().
>
> Create a string with a numeric digits followed by a single letter a thru f
> (as tho' it's base 16).
>
> for  K  in (a,b,c,d, and f ) ,  as.double( '123K') returns NA
> but as.double('123e') returns 123 -- or whatever the first digit is.
>
> Please let me know if there are additional tests I can try .
>
>
> thanks
> Carl Witthoft
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Sarah Goslee (she/her)
http://www.numberwright.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.