Learn R Programming

icd (version 2.2)

set_icd_class: Construct ICD-9 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.

icd_long_data and icd_short_data create data.frames using all the arguments, and sets the class, whereas as.icd_long_data and as.icd_wide_data just set the class of an existing data.frame.

Usage

icd9(x)

as.icd9(x)

icd9cm(x)

as.icd9cm(x)

as.icd10(x)

icd10(x)

as.icd10cm(x, short_code = NULL)

icd10cm(x)

as.icd_long_data(x)

as.icd_wide_data(x)

icd_long_data(...)

icd_wide_data(...)

icd_comorbidity_map(x)

as.icd_comorbidity_map(x)

Arguments

x

object to set class icd9

...

arguments passed on to create a data.frame

warn

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

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.

long or wide format data is always a data frame. It does not carry any other ICD classes, even if it only contains one type of code.

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.

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

# despite exhortation to implement [<- etc, the following seems to work:
j <- as.icd_short_diag(as.icd10(c("A11", "B2222")))
j[2] <- "C33"
stopifnot(is.icd_short_diag(j))
stopifnot(is.icd10(j), is.icd10(j[1]), is.icd10(j[[1]]))
j[[1]] <- "D44001"
stopifnot(is.icd_short_diag(j))
stopifnot(is.icd10(j), is.icd10(j[2]), is.icd10(j[[2]]))
# }

Run the code above in your browser using DataLab