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

load_dictionary not working on json from documentation #72

Open
Addison-Weatherhead opened this issue Aug 15, 2024 · 1 comment
Open

Comments

@Addison-Weatherhead
Copy link

Addison-Weatherhead commented Aug 15, 2024

Calling load_dictionary on the json file provided in the documentation (https://cran.r-project.org/web/packages/ricu/ricu.pdf) (page 34/35), yields this error:

! Cannot merge concept 'glu' due to malformed 'sources' entry
Backtrace:
ricu::load_dictionary(cfg_dirs = "../ricu-extensions/configs/chemistry/")
ricu:::parse_dictionary(...)
ricu:::read_dictionary(name, cfg_dirs)
ricu::get_config(...)
base::Reduce(combine_fun, res, NULL)
ricu (local) f(init, x[[i]])
ricu:::map(combine_sources, x[dups], y[dups], dups)
base::Map(f, ..., USE.NAMES = FALSE)
base::mapply(FUN = f, ..., SIMPLIFY = FALSE)
ricu (local) ''(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]])
ricu:::stop_ricu(...)
rlang::abort(...)
Execution halted

What exactly is wrong with the concept-dict.json:

{
"glu": {
"unit": "mg/dL",
"min": 0,
"max": 1000,
"description": "glucose",
"category": "chemistry",
"sources": {
"mimic_demo": [
{
"ids": [50809, 50931],
"table": "labevents",
"sub_var": "itemid"
}
]
}
}
}

I'm using R 4.2.2, and ricu 0.6.0 (below is the entry for ricu from my renv.lock):

"ricu": { "Package": "ricu", "Version": "0.6.0", "Source": "GitHub", "RemoteType": "github", "RemoteHost": "api.github.com", "RemoteRepo": "ricu-package", "RemoteUsername": "prockenschaub", "RemoteRef": "monkeypatch0.6.0", "RemoteSha": "0969a52747c71ae9f47051d640caa5df2d5169a0", "Requirements": [ "R", "assertthat", "backports", "cli", "curl", "data.table", "fansi", "fst", "jsonlite", "methods", "openssl", "prt", "readr", "rlang", "stats", "tibble", "utils", "vctrs" ], "Hash": "2681cdea2f2f3446691071ea30f745b5" },

@prockenschaub
Copy link
Collaborator

Under the hood, load_dictionary always also loads the base dictionary that comes with ricu. This happens at the end of the subroutine read_dictionary by calling config_path, which itself calls user_config_path and default_config_path. The former can be set via the environment variable RICU_CONFIG_PATH.

The error comes from the fact that the .json in the documentation is copied out of the base dictionary. When you supply your own .json, ricu loads both your .json and the base dictionary and tries to combine the concepts within them. Importantly, only the "sources" part of the concept can be updated, all other entries (e.g., unit, min, max) are expected to stay the same.

So, nothing is wrong with your .json but you tried to perform an update that isn't currently allowed. You can try two fixes that should work:

Create your own concept with it's own name

{
  "glu2": {
    "unit": "mg/dL",
    "min": 0,
    "max": 1000,
    "description": "glucose",
    "category": "chemistry",
    "sources": {
      "other_database": [
        {
          "ids": [50809, 50931],
          "table": "labevents",
          "sub_var": "itemid"
        }
      ]
    }
  }
}

Just update the sources part

{
  "glu": {
    "sources": {
      "mimic_demo": [
        {
          "ids": [999],
          "table": "labevents",
          "sub_var": "itemid"
        }
      ]
    }
  }
}

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