Closed tscheypidi closed 1 year ago
this addresses the problem explained in issue #157. While it does not prevent the initial expansion of the object it detects the issue immediately and throws an error.
All this change is doing is giving a slightly less cryptic error message, without any indication of the duplicated names (which is easy to do and greatly facilitates debugging), iff the magpie
object with duplicated names is passed as the first argument:
> identical(mbind(p, mbind(p, p)), p[, , c(1:2, 1:2, 1:2)])
[1] TRUE
> identical(mbind(mbind(p, p), p), p[, , c(1:2, 1:2, 1:2)])
Error in mbind(mbind(p, p), p) :
Invalid object (number of values changed during mbind). Does the data contain duplicates?
In addition: Warning message:
In .dimextract(x, k, 3, pmatch = pmatch, invert = invert) :
Your dimnames in dim=3 contain duplicates! This might lead to erronous results and bad code performance. Please try to avoid duplicates in dimnames under all circumstances!
What is the point of this warning
if there is a test enforcing exactly that behaviour?
Either magpie
objects support duplicated names (for whatever reason), or they do not. Pick one.
Then, according to your choice, either prevent objects with duplicated names from being created (like it is done for the "spatial" and "temporal" dimensions) and give an informative error message
else {
if (any(duplicated(elems)))
stop("Some names occur more than once! Cannon handle this case! ",
"Duplicated names: ",
paste(unique(elems[duplicated(elems)]), collapse = ", "))
output <- new("magpie", abind::abind(inputs, along = 3))
}
or else prevent objects from exploding inside mbind()
if (!diffdata & ndata(inputs[[1]]) > 1) inputs[[i]] <- inputs[[i]][, , unique(getNames(inputs[[1]]))]
This check detects if the overall object size (sum of length of all objects) changes during
mbind
and throws an error if that happens.