[Rd] grid 4.0 generates wrong results when adding two complex units by sum()

Paul Murrell p@u| @end|ng |rom @t@t@@uck|@nd@@c@nz
Thu Apr 30 02:13:42 CEST 2020


Confirmed.

This is fixed now in R-devel and R-patched.

Thanks for the report!

Paul

On 29/04/20 10:05 pm, Gu, Zuguang wrote:
> Hi,
> 
> 
> In grid 4.0, adding two complex units by `sum()` seems to give wrong results.
> 
> 
> In the following example, `u1 + u2` gives the correct result, but `sum(u1, u2)` also `sum(unit.c(u1, u2))` give the wrong results.
> 
> 
> ```
> 
> library(grid)
> 
> u1 = 0.4*sum(unit(1, "inch"), unit(1, "mm"))
> u2 = 0.1*sum(unit(1, "inch"), unit(1, "mm"))
> u1
> # [1] 0.4*sum(1inches, 1mm)
> u2
> # [1] 0.1*sum(1inches, 1mm)
> 
> # this is correct
> u1 + u2
> # [1] 0.5*sum(1inches, 1mm)
> 
> # but this is wrong, it should return `sum(0.4inches, 0.4mm, 0.1inches, 0.1mm)`, right?
> sum(u1, u2)
> # [1] sum(0.4inches, 0.1mm, 1inches, 1mm)
> sum(unit.c(u1, u2)) # this is also wrong
> # [1] sum(0.4inches, 0.1mm, 1inches, 1mm)
> ```
> 
> Session info:
> 
> ```
> sessionInfo()
> # R version 4.0.0 (2020-04-24)
> # Platform: x86_64-apple-darwin17.0 (64-bit)
> # Running under: macOS Catalina 10.15.4
> #
> # Matrix products: default
> # BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
> # LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
> #
> # locale:
> # [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
> #
> # attached base packages:
> # [1] grid      stats     graphics  grDevices utils     datasets  methods
> # [8] base
> #
> # other attached packages:
> # [1] colorout_1.2-2
> #
> # loaded via a namespace (and not attached):
> # [1] compiler_4.0.0
> ```
> 
> Thanks!
> Zuguang Gu
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul using stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-devel mailing list