This guide is written for people
who work with health databases and may still be learning R: installing a
package from GitHub with pak and setting up the WHO API key
are not obvious steps for them, so they are explained here in detail. If
you are already comfortable with R, you can skip this vignette:
pak::pak("ropensci/ciecl") is all you need to get
started.
The simplest way to install ciecl is with the pak package, which
automatically resolves R and system dependencies.
To also install all optional dependencies (comorbidities, GT tables, ICD-11 API):
The package core (ICD-10 code lookup and search) requires no optional packages. These are the suggested dependencies by task:
| Feature | Package | Installation |
|---|---|---|
Charlson/Elixhauser comorbidity indices with
cie_comorbid() |
comorbidity |
install.packages("comorbidity") |
Formatted HTML tables with cie_table() |
gt |
install.packages("gt") |
| Read MINSAL Excel files | readxl |
install.packages("readxl") |
No additional dependencies: the installation works out of the box.
The CIE-10 functions (the core of the package) work without
credentials. You only need free WHO credentials to use
cie11_search(), which queries the WHO ICD-11
classification.
Security: never write the literal key in your scripts (not even via
api_key = "..."): sharing the code would expose your credentials. The recommended way is theICD_API_KEYenvironment variable, set withusethis::edit_r_environ()(Option B) or viakeyring(Option A). Theapi_keyargument ofcie11_search()exists only for exceptional cases (e.g. multiple keys or environments where env vars cannot be set).
Client ID and a
Client SecretOption A: keyring (recommended)
The keyring
package stores secrets in the OS native keychain (macOS Keychain,
Windows Credential Store, Linux Secret Service), avoiding plain-text
secrets in .Renviron.
# Once: store "client_id:client_secret" in the keychain
keyring::key_set("ciecl_icd11")
# In each session where you use the API
Sys.setenv(ICD_API_KEY = keyring::key_get("ciecl_icd11"))Option B: .Renviron file
Create or edit ~/.Renviron (for example with
usethis::edit_r_environ() if you have usethis
installed) and add:
ICD_API_KEY=your_client_id:your_client_secret
Restart R for it to take effect. Do not commit .Renviron
to Git.
Option C: Current session only (temporary)
The package uses a local SQLite database for efficient searches. It is created automatically on first use, in the user data directory:
You can change that location by setting the
CIECL_CACHE_DIR environment variable before loading the
package. To force a rebuild of the database (for example, after updating
the package):
Check that a CRAN repository is configured in your R session, then install as usual:
Install the system dependencies listed in the “System requirements” section and try the installation again.
Sys.getenv("ICD_API_KEY") must not return an empty
string.