Closed jeromepcollet closed 2 years ago
I see:
> mixed_units(0:3, paste0("m", 0:3))
Mixed units: 1 (1), m (1), m^2 (1), m^3 (1)
0 [1], 1 [m], 2 [m^2], 3 [m^3]
It seems to be a bug in our parser:
units:::R_ut_format(units:::R_ut_parse("m^0"))
#> [1] "1"
set_units(1, "m^0")
#> 1 [1]
but
units:::R_ut_format(units:::R_ut_parse("m/s^0"))
#> [1] "m"
set_units(1, "m/s^0")
#> Error: $ operator is invalid for atomic vectors
#> Did you try to supply a value in a context where a bare expression was expected?
but otherwise, power 0 is allowed and should work.
The use of the power 0 is not so clear. Some examples : t <- set_units(3,"s") set_units(2, "m/s^0") t # does not work at all set_units(2, "m/s0") t # works, but with strange result set_units(2, "m") * t # works
And thanks for your work and reactivity.
Le jeu. 24 juin 2021 à 17:28, Iñaki Ucar @.***> a écrit :
It seems to be a bug in our parser:
units:::R_ut_format(units:::R_ut_parse("m^0"))#> [1] "1" set_units(1, "m^0")#> 1 [1]
but
units:::R_ut_format(units:::R_ut_parse("m/s^0"))#> [1] "m" set_units(1, "m/s^0")#> Error: $ operator is invalid for atomic vectors#> Did you try to supply a value in a context where a bare expression was expected?
but otherwise, power 0 is allowed and should work.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/r-quantities/units/issues/285#issuecomment-867731751, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4FP66XNWZXVCAAFQ6PBQ3TUNFJ5ANCNFSM47H6OTYA .
mixed_units is powerful, for example to define polynomial coefficients. In such a case, something as : x <- mixed_units(1:5, paste0("m/s^",(1:5))) is really handy. But it does not work or the power 0, so it is compulsory to add an instruction for this case. Would-it be possible to extend mixed_units in such a way ?