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

Provides a default method for rescale and rescale_mid #105

Merged
merged 4 commits into from
Jun 15, 2018

Conversation

zeehio
Copy link
Contributor

@zeehio zeehio commented Oct 17, 2017

In #74 and #75 we used a generic S3 method for rescale and rescale_mid. The aim was to handle more types of objects (POSIXt objects...) and to prevent errors like the loss of precision that happened when coercing integer64 to numeric.

While that PR fixed the support for POSIXt types, it also brought issue #102.

There are many numeric types out there that do not inherit from the numeric
class (like the dist object mentioned in #102), compared to the number of cases similar to integer64, where the numeric coercion is wrong.

So there is a trade-off:

  • Not providing the default method in rescale and rescale_mid has the advantage that we only rescale the classes that we know can be rescaled, and the disadvantage that we get issues like rescale stopped working with dist objects #102 when we find a new object. This approach is the current one and it was implemented in rescale() works with Date, POSIXct and POSIXlt objects. #75

  • Providing rescale.default and rescale_mid.default has the advantage of catching all the numeric-like types that do not inherit the numeric class (such as the dist object) and working as expected. However, we risk to deliver wrong results without an error if a case similar to integer64 appeared. This is what this pull request follows.

The changes of getting more issues like #102 are much higher than getting issues like the loss of precision in integer64 objects, so in my opinion this pull request makes sense.

@dpseidel
Copy link
Collaborator

dpseidel commented Jun 9, 2018

Hi @zeehio

We definitely want to address #102 but prefer to be stricter and implement a single new method for dist objects instead of opting for the default method approach you suggest here.

Are you interested in making the necessary changes?

The idea behind r-lib#74 and r-lib#75 was to use an S3 method so we never coerced to numeric
unless we had to. The aim was to prevent future cases similar to the integer64 one
where the coercion to numeric implies a loss of precision.

Reality is that there are many more numeric types out there that do not inherit from the numeric
class (like the dist object mentioned in r-lib#102), compared to the number of cases similar to integer64, where the numeric coercion is wrong.

So there is a trade-off:

- Not providing the `default` methods has the advantage that we only rescale the classes that we know can be rescaled, and the disadvantage that we get issues like r-lib#102 when we find a new object. This is what was implemented in r-lib#75

- Providing `rescale.default` and `rescale_mid.default` has the advantage of catching all the numeric-like types that do not inherit the numeric class (such as the dist object) and working as expected. However, we risk to deliver wrong results without an error if a case similar to integer64 appeared. This is what this commit implements.
@zeehio
Copy link
Contributor Author

zeehio commented Jun 9, 2018

Hi @dpseidel

Thanks for your time working on the scales package and for reviewing this pull requests. Here is the support for dist objects as requested. I reverted my first commit to keep the other solution in the git history, in case we ever need to go back to it. I also rebased the pull request.

Please tell me if there is anything else to be done on my end 😃

@dpseidel dpseidel merged commit a7c8868 into r-lib:master Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants