jackwasey / icd

Fast ICD-10 and ICD-9 comorbidities, decoding and validation in R. NB use main instead of master for default branch.
https://jackwasey.github.io/icd/
GNU General Public License v3.0
240 stars 60 forks source link

Package is down on CRAN #207

Open guilhermejordan opened 3 years ago

colin78 commented 3 years ago

Hi @jackwasey , anything that you need help with in order to get this package back up on CRAN? It's a great package, I would like to see this back up and happy to contribute in some way for this.

magic-lantern commented 3 years ago

Using devtools, it is possible to install the last CRAN archived version of this package:

require(devtools)
install_version("icd", version = "4.0.9", repos = "http://cran.us.r-project.org")
adalisan commented 3 years ago

I would also like to volunteer some time , if it's a diagnosed issue that requires some debugging. From what I have seen in the CRAN build log, a particular test is failing for linux architectures

jackwasey commented 2 years ago

Would be happy for any help, and apologies to everyone for the hiatus. I do think the fixes are small to keep the package on CRAN.

headclone commented 2 years ago

Hello, I am a simple end user, and have used the above devtools() workaround to install the package. How can I update my installation to the CRAN version when it is available, and also how to find out when the package is available on CRAN? Thank you and apologies for the novice question.

magic-lantern commented 2 years ago

I've started looking into this a little and so far am working on getting unit tests to run successfully.

Got the following errors when running devtools::test()

── Failure (Line 15): all available ICD-10-CM data is reported and gettable ─────────────────────
`.get_fetcher_fun(r)()` threw an error.
Message: icd.cache not set and default location ‘/home/me/.cache/R/icd’ is not writable or doesn't exist. Use set_icd_data_dir() to get started.  (The ‘icd.cache’ option is not set, and the default OS-dependent icd data directory does not exist yet. You may also use  ‘set_icd_data_dir("/path/of/your/choice")’ .
Class:   simpleError/error/condition
Running fetcher for: r = icd10cm2014_pc and pc = TRUE
Backtrace:
  1. testthat::expect_error(...)
  6. .get_fetcher_fun(r)()
  9. icd::.parse_icd10cm_year(year = year, dx = dx) R/fetch_icd10cm.R:109:4
 10. icd::.dl_icd10cm_year(year = year, dx = dx) R/parse-icd10.R:43:2
 11. icd::.unzip_to_data_raw(...) R/fetch_icd10cm.R:89:2
 12. icd::get_icd_data_dir() R/to_data_raw.R:29:2

── Error (Line 24): all available ICD-10-CM data is reported and gettable ─────────────────────
Error: icd10cm2014_pc not available in icd, even via as-yet-unloaded lazy data
Backtrace:
 1. icd::.get_anywhere(r, fetch = FALSE)
 2. icd::.absent_action_switch(paste(var_name, "not available in icd, even via as-yet-unloaded lazy data")) R/resource.R:607:2

Tests do not appear to correctly create the necessary and required directories, so I was able to fix the first one by creating the directory specified. After fixing the first issue, the second goes away, but is replaced by this:

Error (test-icd10cm-xml-chapters.R:3:1): (code run outside of `test_that()`)
Error: missing value where TRUE/FALSE needed
Backtrace:
 1. icd:::skip_icd10cm_xml_avail() test-icd10cm-xml-chapters.R:3:0
 2. icd:::skip_no_icd_data_raw(.dl_icd10cm_xml, "skipping test because XML file ICD-10-CM source not available") helper-icd-data.R:104:2
 7. icd:::fun()
 8. icd::.unzip_to_data_raw(...) /home/sethr/icd/R/parse-icd10cm-xml.R:4:2
 9. icd::.confirm_download(msg = dl_msg) /home/sethr/icd/R/to_data_raw.R:54:4

I haven't figured out this one yet.

nathandalton commented 2 years ago

I've been able to get the devtools::test call to not fail by altering the following in the to_data_raw.R code:

if (!file.exists(file_path)) {
    .msg(
      "Unable to find downloaded file at: ",
      file_path, ". Attempting download..."
    )
    if (!.confirm_download(msg = dl_msg)) {
      return()
    }
    ok <- .unzip_single(
      url = url,
      file_name = file_name,
      save_path = file_path,
      ...
    )
    stopifnot(ok)
  }

I essentially override the .confirm_download(msg = dl_msg) call by changing (msg = dl_msg) to (msg = TRUE), as follows (.confirm_download() is located in resource.R:

if (!file.exists(file_path)) {
    .msg(
      "Unable to find downloaded file at: ",
      file_path, ". Attempting download..."
    )
    if (!.confirm_download(msg = TRUE)) {
      return()
    }
    ok <- .unzip_single(
      url = url,
      file_name = file_name,
      save_path = file_path,
      ...
    )
    stopifnot(ok)
  }

Which correctly employs the .confirm_download() call and actually brings up a pop-up confirmation window, as it should:


.confirm_download <- function(msg = NULL) {
  if (!.offline()) {
    if (!.exists_icd_data_dir()) {
      set_icd_data_dir()
    }
    return(TRUE)
  }
  ok <- FALSE
  if (.interact()) {
    message(
      "icd needs to download and/or parse data.",
      "It will be saved in an OS-specific data directory, ",
      "or according to the R option: ", sQuote("icd.cache")
    )
    if (.verbose() && !is.null(msg)) message(msg)
    ok <- isTRUE(
      askYesNo(
        "May I download and cache a few MB per ICD edition as needed?"
      )
    )
  }
  .set_opt("offline" = !ok)
  if (!ok) .absent_action_switch("Unable to get permission to download data.")
  ok
}

However, I haven't been able to quite figure out the exact reason why this change works. Given that the error thrown when running devtools::test is missing value where TRUE/FALSE needed, I figured that giving it a TRUE value would help. But as for why confirm_download() isn't returning TRUE/FALSE, I can't say just yet.

UPDATE

Having re-run the devtools::test call, it passes successfully; I'm assuming this is because the necessary data has been cached, which results in .confirm_download no longer being called? Not too sure...

Nonetheless, it appears that the above is not the reason precluding icd from being back up on CRAN; it looks like the refactor tests are failing for Linux, as mentioned by adalisan above.

Running the call that fails (in test-refactor.R) on Windows passes the test:

test_that("new factor has empty levels when necessary", {
    expect_equal(
        refactor(factor("a"), levels = NA, na.rm = FALSE, exclude_na = TRUE),
        factor(NA)
    )
})

Changing this line to refactor(f, levels = NA, na.rm = FALSE, exclude_na = FALSE) and factor(NA) to factor(NA, exclude = NULL) as it appears in the CRAN package check results appears to replicate the error:

> test_that("new factor has empty levels when necessary", {
+     expect_equal(
+         refactor(factor("a"), levels = NA, na.rm = FALSE, exclude_na = FALSE),
+         factor(NA, exclude = NULL)
+     )
+ })
-- Failure (Line 2): new factor has empty levels when necessary ---------------------
refactor(factor("a"), levels = NA, na.rm = FALSE, exclude_na = FALSE) not equal to factor(NA, exclude = NULL).
1, NA mismatch

Looking at the history of test.refactor.R here (diff 222, line 123 in right column), it looks like exclude = NULL is included. However, the same is not included in the file located in the repo here (line 119).

I'm not sure how helpful this is in fixing this issue.

Lilyhappiness commented 1 year ago

Using devtools, it is possible to install the last CRAN archived version of this package:

require(devtools)
install_version("icd", version = "4.0.9", repos = "http://cran.us.r-project.org")

These lines do not work for me. Do you have any updates on how to get the ICD package downloaded?

iacobus42 commented 1 year ago

Try devtools::install_github("jackwasey/icd")

On Tue, Mar 7, 2023, 7:10 PM Lily Li @.***> wrote:

Using devtools, it is possible to install the last CRAN archived version of this package:

require(devtools) install_version("icd", version = "4.0.9", repos = "http://cran.us.r-project.org")

These lines do not work for me. Do you have any updates on how to get the ICD package downloaded?

— Reply to this email directly, view it on GitHub https://github.com/jackwasey/icd/issues/207#issuecomment-1459111259, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHMKEL2NP2Y75QLMTOQK73W27MBPANCNFSM4SSXZQ5Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

twobunnyrabbit commented 1 year ago

Try devtools::install_github("jackwasey/icd")

I can confirm this works on R version 4.3.1 (MacOS 12).

viktorzou commented 1 month ago

Try devtools::install_github("jackwasey/icd")

I can confirm this works on R version 4.3.1 (MacOS 12).

doesn't work for me, devtools::install_version("icd", version = "4.0.9", repos = "http://cran.us.r-project.org") also wont work

would be great to have the package back running...