-
Notifications
You must be signed in to change notification settings - Fork 10
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
add im- and export for IIASA xlsx files #38
Conversation
R/write.IAMCxlsx.R
Outdated
setdiff(colnames(.), default_columns), | ||
last(default_columns)) %>% | ||
arrange(.data$Period) %>% | ||
mutate(!!sym('Value') := ifelse(! is.finite(!!sym('Value')) | !!sym('Value') == "", 0, !!sym('Value'))) %>% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is that desired behaviour? Seems to me putting/leaving
NA
(or "N/A" or "n_a" or whatever IIASA is using) instead of valid-looking zeros would make more sense … -
is more concise.
mutate(Value = ifelse(!is.finite(.data$Value) | .data$Value == "", 0, .data$Value))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asked the IIASA admins about that. I just adopted Jeromes solution for NGFS, but maybe this is not accurate (anymore?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, an easier (and probably faster, but who is counting) way would be
- arrange(.data$Period) %>%
- mutate(!!sym('Value') := ifelse(! is.finite(!!sym('Value')) | !!sym('Value') == "", 0, !!sym('Value'))) %>%
- pivot_wider(names_from = 'Period', values_from = 'Value')
+ filter(is.finite(.data$Value), '' != .data$Value) %>%
+ pivot_wider(names_from = 'Period', names_sort = TRUE,
+ values_from = 'Value', values_fill = 0)
If IIASA says "use 'n_a'
", you will have to convert to strings first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agreed with IIASA that writing files with empty cells is best. Using NA
as values_fill
leads to empty cells in the xlsx, so I implemented it like that, no need to convert to string though, luckily.
R/read.quitte.R
Outdated
periods <- names(data)[grep("^[0-9]{4}$", names(data))] | ||
data <- as.quitte(pivot_longer(data, all_of(periods), names_to = 'period', values_drop_na = drop.na)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quite long-winded … why not pivot_longer(matches("^[0-9]{4}$")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I copied that from this line…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… that actually predates match()
(and pivot_longer()
, for that matter). :p
@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q: Should we also add something like this?
|
Sure. |
Opted for |
write.xlsx
as function name as it already exists inxlsx
package), whether tests are sufficient etc.write.mif
.