Create unit from string with Unitful.jl

Is it possible to create a unit from a string with the Unitful.jl package at runtime without using eval?

Something like this:

unit_str = "mol/L"
unitful_unit = unit(unit_str)

I only found u"..." and @u_str, where string interpolation is not possible imho.

Edit: In the case of standalone units, it is possible to do this:

unit_str = "m"
getfield(Unitful, Symbol(unit_str))

You may be interested in following Parsing of units from strings by c42f · Pull Request #298 · PainterQubits/Unitful.jl · GitHub

3 Likes