Provides a default method for rescale and rescale_mid #105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #74 and #75 we used a generic S3 method for
rescale
andrescale_mid
. The aim was to handle more types of objects (POSIXt objects...) and to prevent errors like the loss of precision that happened when coercinginteger64
tonumeric
.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 inrescale
andrescale_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. #75Providing
rescale.default
andrescale_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.