Hi! Yes, Peter had the right end of the
stick; Eidos has no way to represent "lack of an object" the way that
nullptr in C/C++ does, or that NA in R does. There is no value that you
can mix together with mutation objects in a vector represent the lack
of a mutation object at a given position. NULL doesn't work because it
is not like NA; it is its own data type, and data types cannot be mixed
within a single vector in Eidos. And c(NULL, NULL) is NULL, so you
can't make a vector out of NULL either; size(NULL) is zero.
That said, there are a variety of ways that you could approach this,
starting with the ones you've explored:
1. Use an existing mutation as a placeholder; far from ideal since you
can't tell the difference between "no mutation object" and the
particular mutation object you've arbitrarily chosen as a placeholder.
2. Make a custom mutation as a placeholder, otherwise unused in your
model; the is somewhat better, but ugly.
3. Make a Dictionary, using integers as keys, with NULL in the keys 0-4;
you are then free to replace the value for any key with a mutation
object. This is not bad, I think, but is probably not terribly
efficient. Whether that matters depends, of course, on what you're
really trying to achieve, which you haven't told us, and which might be
helpful to know. :-> Dictionary substitutes for a lot of data
structures in other languages; since Eidos provides no way to define new
types/structs/classes; if you want "a bag of information that behaves
in a particular way", doing it with Dictionary is often the best path in
Eidos.
4. Keep a vector of mutation IDs, rather than mutations, and use -1 as a
placeholder for "no mutation". You could use subsetMutations() to look
up any given ID (provided it is not -1), or you could use match() with a
bit of elbow grease to look up the mutations that match a whole vector
of IDs. The lookup part of this solution is a bit annoying, but the
rest is straightforward.
5. Keep a separate variable for each index: mut0, mut1, mut2, mut3,
mut4. Initialize them all to NULL initially, and then you can
individually set/get the values, although "subsetting" with an integer
index would be annoying and inefficient. Depending on the nature of the
problem, this might work just fine, or not.
6. Come up with a different approach to your problem (whatever it is)
that doesn't require this particular data structure. This is probably
the easiest, if it is possible. We could try to help with that, if you
told us what the actual problem is. :->
Good luck!
Cheers,
-B.
Hanbin Lee wrote on 10/1/25 6:47 PM: