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

Gu, Zuguang z@gu @end|ng |rom dk|z-he|de|berg@de
Wed Apr 29 12:05:54 CEST 2020


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]]



More information about the R-devel mailing list