Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add support for setNumericRounding(4) #1898

Closed
rmcgehee opened this issue Nov 2, 2016 · 2 comments
Closed

[Request] Add support for setNumericRounding(4) #1898

rmcgehee opened this issue Nov 2, 2016 · 2 comments

Comments

@rmcgehee
Copy link

rmcgehee commented Nov 2, 2016

Hi,
I use PostgreSQL to store my data, and will generally store numeric values with the 4-byte REAL type rather than the 8-byte FLOAT type because the extra precision is not needed and making smaller tables improves query performance.

However, this means that when I bring the data into R, equivalent values may differ at the 6th or 7th significant digit. As such, I'd love if I could setNumericRounding(4) so that the data.table package would treat values as equivalent if they match in the first four bytes only.

In case this is an easy fix, and you were just waiting for a use case like mine, please consider supporting higher values for setNumericRounding. I certainly like the idea behind the function, and only wish it could round a bit more.

Thanks!
Robert

@MichaelChirico
Copy link
Member

It does look simple enough to support this (#6083). If you have any minimal working example we could test, that would be great.

OTOH, it does seem like this is something to resolve with a package extension supporting more general data structures than available in base R. If the fix in #6083 has some flaws, I would rather close this as out-of-scope than pursue any really deep fix.

@MichaelChirico
Copy link
Member

Per the PostgreSQL docs, the REAL type you're after is actually single-precision floating point numbers:

https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-FLOAT
https://en.wikipedia.org/wiki/Single-precision_floating-point_format

Therefore I doubt that setNumericRounding(4) is actually what you want. Given the complications uncovered in #6083, I would not pursue that PR further.

Glancing around, I find the {float} package supports single-precision numbers:

https://cran.r-project.org/web/packages/float/index.html

If you run into issues working with single-precision vectors from {float}, please file a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants