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

Unexpected behavior of magpie_expand #166

Closed
orichters opened this issue Feb 26, 2024 · 1 comment
Closed

Unexpected behavior of magpie_expand #166

orichters opened this issue Feb 26, 2024 · 1 comment
Assignees

Comments

@orichters
Copy link
Contributor

orichters commented Feb 26, 2024

library(magclass)
t <- c(1995, 2005, 2015)
s <- c('AFR', 'CPA')
A <- dimSums(maxample('pop')[s,t,'A2'], 3)
B <- dimSums(maxample('pop')[s,t[-2],'B1'], 3)
> A
An object of class "magpie"
, , 1

     t
i         y1995   y2005   y2015
  AFR  552.6664  696.44  889.18
  CPA 1280.6350 1429.53 1518.46

> B
An object of class "magpie"
, , 1

     t
i         y1995   y2015
  AFR  552.6664  932.04
  CPA 1280.6350 1499.74

Now, running magpie_expand on B with A as ref:

magpie_expand(B, A)
An object of class "magpie"
, , 1

     t.t1
i     y1995.y1995 y1995.y2015 y2005.y1995 y2005.y2015 y2015.y1995 y2015.y2015
  AFR    552.6664      932.04    552.6664      932.04    552.6664      932.04
  CPA   1280.6350     1499.74   1280.6350     1499.74   1280.6350     1499.74

That is not how I understand the function, I would have expected something with the dimension of A

Digging into the code, it seems that magclass:::magpie_expand_dim(B, A, dim = 2) shows this error, so I guess the problem is somewhere here: Before this line, the object are defined as follows:

> lx
$t
[1] "y1995" "y2015"

> lref
$t
[1] "y1995" "y2005" "y2015"

> match(lx, lref)
NA

So it cannot match anything. Unclear whether that is intended.

@tscheypidi
Copy link
Member

This is the intended behavior. The time dimensions have different elements, hence they are treated as different dimensions.

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

2 participants