[Rd] preserve names in grid::unit() ?
David Firth
d@||rth @end|ng |rom w@rw|ck@@c@uk
Wed Aug 27 16:08:52 CEST 2025
I am asking here first, rather than filing a feature request directly. It concerns a function in the grid package, maintained by R-core.
Is there a reason why grid::unit(x, units) does not preserve the names (if such exist) from vector x?
I have a use-case where that would be helpful. But maybe there is some obstacle that I have not thought of?
Current behaviour seems to be:
> x <- 7:9
> names(x) <- letters[1:3]
> x
a b c
7 8 9
> z <- grid::unit(x, "native")
> z
[1] 7native 8native 9native
> str(z)
'simpleUnit' num [1:3] 7native 8native 9native
- attr(*, "unit")= int 4
> class(z)
[1] "simpleUnit" "unit" "unit_v2"
## Now assign names
> names(z) <- names(x)
> z
[1] 7native 8native 9native
> names(z)
[1] "a" "b" "c"
> str(z)
'simpleUnit' Named num [1:3] 7native 8native 9native
- attr(*, "unit")= int 4
- attr(*, "names")= chr [1:3] "a" "b" "c"
I would welcome any comments or suggestions.
Thanks -- David
More information about the R-devel
mailing list