Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass string to @u_str #713

Closed
matthewelmer-tamu opened this issue Mar 18, 2024 · 1 comment
Closed

Can't pass string to @u_str #713

matthewelmer-tamu opened this issue Mar 18, 2024 · 1 comment

Comments

@matthewelmer-tamu
Copy link

matthewelmer-tamu commented Mar 18, 2024

I would like to pass a string to @u_str to create a unit, but it doesn't work:

julia> a = "km"
"km"

julia> @u_str(a)
ERROR: LoadError: MethodError: no method matching parse(::Symbol)

Closest candidates are:
  parse(::AbstractString; filename, raise, depwarn)
   @ Base meta.jl:276
  parse(::AbstractString, ::Integer; filename, greedy, raise, depwarn)
   @ Base meta.jl:236

Stacktrace:
 [1] var"@u_str"(__source__::LineNumberNode, __module__::Module, unit::Any)
   @ Unitful ~/.julia/packages/Unitful/R4J37/src/user.jl:630
in expression starting at REPL[100]:1

I'm parsing a json file which contains values and a string representation of their units, so I can't just pass a string literal.

@matthewelmer-tamu
Copy link
Author

matthewelmer-tamu commented Mar 18, 2024

Nevermind, I just found the undocumented uparse, which serves my purpose.

julia> a = "km"
"km"

julia> Unitful.uparse(a)
km

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant