Skip to content

Commit

Permalink
Everything works with CRAN-check
Browse files Browse the repository at this point in the history
  • Loading branch information
gforge committed May 14, 2014
1 parent a527e4d commit e556b66
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: comorbidities.icd10
Type: Package
Title: Categorizes ICD-9-CM and ICD-10 codes based on published comorbidity
indices
Version: 0.4
Date: 2014-05-12
Version: 0.5
Date: 2014-05-14
Author: Max Gordon
Maintainer: Max Gordon <max@gforge.se>
Description: Methods to categorize ICD-9-CM and ICD-10 codes into sensible
Expand All @@ -19,7 +19,8 @@ LazyLoad: yes
URL: https://github.com/gforge/comorbidities.icd10
BugReports: https://github.com/gforge/comorbidities.icd10/issues
Imports:
plyr (>= 1.8.1)
plyr (>= 1.8.1),
stringr
Suggests:
testthat (>= 0.8)
Encoding: UTF-8
Expand Down
24 changes: 15 additions & 9 deletions R/peprocessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ preproc.Swedich.ICD9 <- function(icd, icd_ver){
substr(icd, 1, 4),
icd)

# Return the icd_version info as this may be used
# Return the icd_version info as this may be used
# for other purposes and save time
attr(icd, "icd_ver") <- icd_ver

return(icd)
}

Expand All @@ -105,10 +106,12 @@ preproc.Swedich.ICD9 <- function(icd, icd_ver){
#' @export
#' @family preprocessor functions
preproc.strip.dot <- function(icd, icd_ver){
if (is.data.frame(codes)) {codes <- as.matrix(codes)}
if (is.data.frame(icd)) {icd <- as.matrix(icd)}

icd <- gsub(".", "", codes, fixed=TRUE)
attr(icd, "icd_ver") <- icd_ver
icd <- gsub(".", "", icd, fixed=TRUE)
if (!missing(icd_ver)){
attr(icd, "icd_ver") <- icd_ver
}
return(icd)
}

Expand Down Expand Up @@ -140,11 +143,14 @@ preproc.code.splitter <- function(icd, icd_ver,
trim = TRUE){
if (trim){ icd <- str_trim(icd) }
code_list <- strsplit(icd, split_str)
# Convert the icd_versions to match to the split strings
times <- sapply(code_list, length)
icd_ver <- rep(icd_ver, times=times)

icd <- unlist(code_list)
attr(icd, "icd_ver") <- icd_ver

if (!missing(icd_ver)){
# Convert the icd_versions to match to the split strings
times <- sapply(code_list, length)
icd_ver <- rep(icd_ver, times=times)
attr(icd, "icd_ver") <- icd_ver
}

return(icd)
}
36 changes: 18 additions & 18 deletions tests/testthat/test-preproc.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ test_that("code_splitter", {


test_that("Check Swedish ICD-9 translator",{
expect_equal(preproc.Swedich.ICD9("456A"), "4560")
expect_equal(preproc.Swedich.ICD9("456X"), "4569")
expect_equivalent(preproc.Swedich.ICD9("456A"), "4560")
expect_equivalent(preproc.Swedich.ICD9("456X"), "4569")
expect_error(preproc.Swedich.ICD9("3133"),
info="If no letter at the fourth position there is an error")
expect_error(preproc.Swedich.ICD9("313M"),
info="M is not a valid letter at the fourth position and should give an error")

expect_equal(preproc.Swedich.ICD9(c("456A", "873B")),
c("4560", "8731"))
expect_equivalent(preproc.Swedich.ICD9(c("456A", "873B")),
c("4560", "8731"))


expect_equal(preproc.Swedich.ICD9(c("456a", "873b")),
c("4560", "8731"))
expect_equivalent(preproc.Swedich.ICD9(c("456a", "873b")),
c("4560", "8731"))

expect_equal(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9,10)),
c("4560", "8731", "M161"))
expect_equivalent(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9,10)),
c("4560", "8731", "M161"))

expect_error(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9,9)),
Expand All @@ -62,14 +62,14 @@ test_that("Check Swedish ICD-9 translator",{
expect_error(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9)),
info="The funciton should complain if there is a mismatch between ICD-codes and the true value")

expect_equal(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9,FALSE)),
c("4560", "8731", "M161"))

expect_equal(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=FALSE),
c("4560", "8731", "M161"))
expect_equivalent(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=c(9,9,FALSE)),
c("4560", "8731", "M161"))
expect_equivalent(preproc.Swedich.ICD9(icd=c("456a", "873b", "M161"),
icd_ver=FALSE),
c("4560", "8731", "M161"))
})

test_that("Advanced Swedish pre-processor test",{
Expand All @@ -90,7 +90,7 @@ test_that("Advanced Swedish pre-processor test",{
icd <- preproc.code.splitter(icd, icd_ver)
preproc.Swedich.ICD9(icd, attr(icd, "icd_ver"))
}

# The most important part is that this passes
expect_true(is.list(cmrbdt.calc(swe_test_df,
id_column="ID", icd_columns=c("MainICD", "CoICD"),
Expand Down

0 comments on commit e556b66

Please sign in to comment.