joaomacalos / sfcr

Simulate Stock-Flow Consistent Models
Other
23 stars 11 forks source link

Error in sfcr_set_index #9

Open Codo-der-Dritte opened 8 months ago

Codo-der-Dritte commented 8 months ago

The error in sfcr_set_index is caused when if(){}else{} condition are used in the equations of the model.

This is the error message:

> index <- sfcr_set_index(model_eqs)
Error in `dplyr::mutate()`:
ℹ In argument: `id = 1:length(eqs)`.
Caused by error:
! `id` must be size 190 or 1, not 146.
sfcr_set_index <- function(eqs) {
  eqs = model_eqs
  abortifnot(inherits(eqs, "sfcr_set"), "Please supply a list of equations created with `sfcr_set()`.")

    purrr::map_df(eqs, ~ tibble::enframe(name = "id", deparse(.x, width.cutoff = 500))) %>%
    dplyr::mutate(id = 1:length(eqs)) %>%
    tidyr::separate(.data$value, into = c("lhs", "rhs"), " ~ ")
}

The error happens in this part of the code purrr::map_df(eqs, ~ tibble::enframe(name = "id", deparse(.x, width.cutoff = 500))) as the if(){}else{} condition is split up in to several rows. This can be seen in the screenshot I attached.

Bildschirmfoto 2024-02-07 um 13 54 15