Learn R Programming

icd (version 3.3)

set_icd_class: Construct ICD-9 and ICD-10 data types

Description

Takes an R structure and sets class to an ICD type. In the case of ICD-9 and ICD-10 codes, if a particular sub-type is set, e.g. ICD-9-CM (icd9cm), then an ICD-9 class (icd9) is also set.

Usage

icd9(x)

as.icd9(x)

icd9cm(x)

as.icd9cm(x)

as.icd10(x)

icd10(x)

as.icd10cm(x, short_code = NULL)

icd10cm(x)

comorbidity_map(x)

as.comorbidity_map(x)

as.icd_comorbidity_map(...)

Arguments

x

object to set class icd9

...

arguments passed on to other functions

warn

single logical value, if TRUE will gives warning when converting between types. ICD-9 to ICD-10 will cause an error regardless.

Deprecated function names

Future versions of icd will drop the icd_ prefix. For example, charlson should be used in favor of icd_charlson. To distinguish icd function calls, consider using the prefix icd:: instead, e.g., icd::charlson. Functions which specifically operate on either ICD-9 or ICD-10 codes or their sub-types will retain the prefix. E.g. icd9_comorbid_ahrq. icd specific classes also retain the prefix, e.g., icd_wide_data.

Details

The as. function e.g. as.icd9, do checking and try to put multiple classes in a nice order. Calling the bare constructor, e.g. icd9 just prepends the new class and returns without any checks. The latter is much faster, but for most uses, as.icd9 and siblings would be better.

Some features make more sense as attributes. E.g. setting code type to short or decimal.

Using attributes instead of class is a better fit for the data. It simplifies S3 dispatch, and appears to be very fast to get or set using the built-in R functions.

See Also

icd_long_data

Examples

Run this code
# NOT RUN {
x = as.icd10("A1009")
attr(x, "icd_short_diag") <- TRUE
x
attributes(x) <- list(icd_short_diag = NULL)
x

y <- as.decimal_diag(as.icd10("A10.09"))
y
is.short_diag(y)

j <- as.short_diag(as.icd10(c("A11", "B2222")))
j[2] <- "C33"
stopifnot(is.short_diag(j))
stopifnot(is.icd10(j), is.icd10(j[1]), is.icd10(j[[1]]))
j[[1]] <- "D44001"
stopifnot(is.short_diag(j))
stopifnot(is.icd10(j), is.icd10(j[2]), is.icd10(j[[2]]))
# }

Run the code above in your browser using DataLab