Warning: newbie here. Suppose I have something like
using ComponentArrays
p = ComponentArray()
p = ComponentArray(p; thing = 1)
tmp = ComponentArray{Int32}()
tmp = ComponentArray(tmp; a = 2)
tmp = ComponentArray(tmp; b = 3:4)
p = ComponentArray(p; other = tmp)
Is there a way to access p.other
fields (or “top level” ones, for that matter) using something like str="b"
, then p.other.str
?
I am thinking of the analogy in R
, where I would, in a list, access entries by using p$other[[str]]
as opposed to p$other$b
if I know that I want to access b
.
I have a lookup table from which I am getting the field I want to use. I could work in the other direction (iterate on the keys of p.other
and go find the info in my lookup table), but there are instances where my lookup table has 10 entries while my p.other
has millions (my guess is that the keys are well indexed and quickly searched, so finding a key is fast).
So and also out of curiosity, I was wondering if there’s a way to do the equivalent of my R
statement.
I have so far worked out that I could find the index of b
in the keys of p.other
using findfirst
, but for that, I need to figure out how to convert str
to a symbol… That will be my next question if there is no way to directly do some direct equivalent of the R
statement.