Closed jeromepcollet closed 1 month ago
Are you having trouble with the issue buttons? :)
Not sure what's your point here, because both examples fail. Do not use deparse_unit
for this. This works:
x <- set_units(1, kg/m)
y <- set_units(1, units(x), mode="standard")
x <- set_units(1, kg/m3)
y <- set_units(1, units(x), mode="standard")
Sorry for my misuse of buttons. My constraint is that I have to store units in a text file before resetting them to other variables. And I forgot the use of "standard". Now I think following examples are OK : first works, second fails ############ library(units)
lineic_density <- set_units(1, kg/m) lineic_density lineic_density_unity <- deparse_unit(lineic_density) lineic_density_unity other_lineic_density <- set_units(2, lineic_density_unity, mode = "standard") other_lineic_density
density <- set_units(1, kg/m3) density density_unity <- deparse_unit(density) density_unity other_density <- set_units(2, density_unity, mode = "standard") other_density
There's certainly an open bug in our parser when there's a m3
instead of m^3
, but that's #221. About the main point of your use case, see my comment above and use units()
instead of deparse_unit()
for this.
Ah, sorry, I didn't catch this:
My constraint is that I have to store units in a text file before resetting them to other variables.
In such a case, specify your units as km/m^3
or "km m-3"
to circumvent the issue with #221.
OK, I do not see exactly how to use https://github.com/r-quantities/units/issues/221, I will look further. I make my need more precise : I wanted to get the units automatically from a previous data-frame, to set these units on a new data.frame. Thank you for your help, I see my need is very specific.
OK, I do not see exactly how to use #221, I will look further.
No, you don't need to "use" #221. I mean that our parser has a problem parsing m3
vs m^3
, and this is reported in #221, so no need to keep this issue open too.
I make my need more precise : I wanted to get the units automatically from a previous data-frame, to set these units on a new data.frame. Thank you for your help, I see my need is very specific.
If you use the ^
character to specify powers, i.e. km/m^3
instead of km/m3
, your workflow above should work fine.
I have some variables, and I want to set their unities to other unitless variables. Among them, some are volumic variables, and the process fails, because the denominator is deparsed as "m3-1"
examples
works
fails