ricu package in R Studio: Damaged or incomplete file header

Hello Posit Community!
I am urgently looking for someone who can help me with an error I am experiencing when trying to use the "ricu" package in R.

I successfully installed and loaded the package "ricu", however once I try to use its basic commands (e.g., concept_availability( )) I always get the same error: Error in metadata_fst(path, old_format) : It seems the file header was damaged or incomplete

explain_dictionary()
#> Error in explain_dictionary(): could not find function "explain_dictionary"

The traceback( ) is the following

32: stop(metadata)
31: metadata_fst(path, old_format)
30: FUN(X[[i]], ...)
29: lapply(files, fst::fst)
28: eval(assertion, env)
27: eval(assertion, env)
26: doTryCatch(return(expr), name, parentenv, handler)
25: tryCatchOne(expr, names, parentenv, handlers[[1L]])
24: tryCatchList(expr, classes, parentenv, handlers)
23: tryCatch({
        eval(assertion, env)
    }, assertError = function(e) {
        structure(FALSE, msg = e$message)
    })
22: see_if(..., env = env, msg = msg)
21: assert_that(is.list(x), all(vapply(x, inherits, logical(1L), 
        "fst_table")))
20: make_prt(lapply(files, fst::fst))
19: prt::new_prt(files)
18: new_src_tbl(fil, col, tbl, src_prefix(src), env)
17: (function (value) 
    {
        if (!missing(value)) {
            if (is.null(value)) {
                src_tbl_cache <<- NULL
            }
            else {
                warn_ricu("Cannot update read-only table `{tbl_name(tbl)}` of data\n                     source `{src_name(src)}`.", 
                    "assign_src_tbl")
            }
        }
        if (all(file.exists(fil))) {
            if (is.null(src_tbl_cache)) {
                src_tbl_cache <<- new_src_tbl(fil, col, tbl, src_prefix(src), 
                    env)
            }
            return(src_tbl_cache)
        }
        msg_ricu("Data for `{src_name(src)}` is missing", "miss_tbl_msg", 
            tbl_cfg = tbl)
     ...
16: get0(x, envir = env, inherits = FALSE)
15: doTryCatch(return(expr), name, parentenv, handler)
14: tryCatchOne(expr, names, parentenv, handlers[[1L]])
13: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch(get0(x, envir = env, inherits = FALSE), miss_tbl_msg = function(msg) msg[["tbl_cfg"]])
11: safe_tbl_get(tbl, env)
10: is_src_tbl(safe_tbl_get(tbl, env))
9: FUN(X[[i]], ...)
8: vapply(x, fun, logical(length), ..., USE.NAMES = use_names)
7: lgl_ply(tbls, is_tbl_avail, env, use_names = TRUE)
6: FUN(X[[i]], ...)
5: lapply(src, src_tbl_avail)
4: src_data_avail(src)
3: is_data_avail(attached_srcs())
2: load_dictionary(...)
1: explain_dictionary( )

I am new to R and I already tried to solve this issue for several hours now, I would be super thankful if someone could help me out!

Here's what should be happening

library(fst)
# Sample dataset
x <- data.frame(
  First = 1:10,
  Second = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
  Last = sample(LETTERS, 10))
# Write to fst file
fst_file <- tempfile(fileext = ".fst")
write_fst(x, fst_file)
# Display meta information
metadata_fst(fst_file)
#> <fst file>
#> 10 rows, 3 columns (file79b5a5c2695f0.fst)
#> 
#> * 'First' : integer
#> * 'Second': logical
#> * 'Last'  : character

If this example works, then it's possible that the path is incorrect or the file is not an fst object in the call you are trying to make

1 Like

Hello technocrat, thank you so much for your answer!!

I tried out the example that you posted and it is working. However, I am still having problems with the "ricu" package. How could I fix an incorrect path or a file that is not an fst object?

The error I am getting when I try to load the "ricu" package now is:

> library(ricu)
fstcore package v0.9.12
(OpenMP was not detected, using single threaded mode)
Error: package or namespace load failed for β€˜ricu’:
 .onAttach failed in attachNamespace() for 'ricu', details:
  call: metadata_fst(path, old_format)
  error: It seems the file header was damaged or incomplete 

Thanks again for your help :slight_smile:

I wasn’t able to get rici installed under Ubuntu (which is weird). I’ll try again later tonight on macOS. If all else fails, I’ll try to parse the rici source code.

1 Like

Here's what I get on the M1

library(ricu)
#> 
#> ── ricu 0.5.4 ──────────────────────────────────────────────────────────────────
#> 
#> The following data sources are configured to be attached:
#> (the environment variable `RICU_SRC_LOAD` controls this)
#> 
#> βœ– mimic: 0 of 26 tables available
#> βœ” mimic_demo: 25 of 25 tables available
#> βœ– eicu: 0 of 31 tables available
#> βœ” eicu_demo: 31 of 31 tables available
#> βœ– hirid: 0 of 5 tables available
#> βœ– aumc: 0 of 7 tables available
#> βœ– miiv: 0 of 27 tables available
#> 
#> ────────────────────────────────────────────────────────────────────────────────
# if necessary
# install.packages(
#   c("mimic.demo", "eicu.demo"),
#   repos = "https://eth-mds.github.io/physionet-demo"
# )

src  <- "mimic_demo"
demo <- c(src, "eicu_demo")

head(explain_dictionary(src = demo))
#>       name     category            description
#> 1      abx  medications            antibiotics
#> 2 adh_rate  medications       vasopressin rate
#> 3      adm demographics patient admission type
#> 4      age demographics            patient age
#> 5      alb    chemistry                albumin
#> 6      alp    chemistry   alkaline phosphatase

Try reinstalling from CRAN if you installed from github and github if you installed from CRAN

remotes::install_github("eth-mds/ricu")
1 Like

Hi, I am running R Studio on a macOS M2. In the beginning "ricu" was working fine, but somehow I messed things up and I unfortunately don't know what I did wrong.

When I install "ricu" from GitHub now (before I used CRAN) I get the following error message:

> remotes::install_github("eth-mds/ricu")
Downloading GitHub repo eth-mds/ricu@HEAD
Running `R CMD build`...
* checking for file β€˜/private/var/folders/bg/cl8k5pgj6fb4hfb4kkzb0wvh0000gn/T/RtmpEr4lNX/remotesbde73cb9446d/eth-mds-ricu-09902bd/DESCRIPTION’ ... OK
* preparing β€˜ricu’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building β€˜ricu_0.5.4.tar.gz’
* installing *source* package β€˜ricu’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for β€˜ricu’:
 .onAttach failed in attachNamespace() for 'ricu', details:
  call: metadata_fst(path, old_format)
  error: It seems the file header was damaged or incomplete
Error: loading failed
Execution halted
ERROR: loading failed
* removing β€˜/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/ricu’
Warning message:
In i.p(...) :
  installation of package β€˜/var/folders/bg/cl8k5pgj6fb4hfb4kkzb0wvh0000gn/T//RtmpEr4lNX/filebde7273b6f40/ricu_0.5.4.tar.gz’ had non-zero exit status

Do you know what that means?

Maybe adding to this, when I then try to load the package it fails:

> library(ricu)
Warning message:
In read.dcf(file.path(p, "DESCRIPTION"), c("Package", "Version")) :
  cannot open compressed file '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/ricu/DESCRIPTION', probable reason 'No such file or directory'

However, when I try to install again with CRAN, I get the popup "one or more of the packages to be updated are currently loaded" and I get this error

install.packages("ricu")
Error in install.packages : Updating loaded packages

Try saving this in the directory as DESCRIPTION


Package: ricu
Title: Intensive Care Unit Data with R
Description: Focused on (but not exclusive to) data sets hosted on PhysioNet
    (<https://physionet.org>), 'ricu' provides utilities for download, setup
    and access of intensive care unit (ICU) data sets. In addition to
    functions for running arbitrary queries against available data sets, a
    system for defining clinical concepts and encoding their representations
    in tabular ICU data is presented.
Version: 0.5.4
Authors@R: c(
    person(given = "Nicolas",
           family = "Bennett",
           role = c("aut", "cre"),
           email = "r@nbenn.ch"),
    person(given = "Drago",
           family = "Plecko",
           role = c("aut"),
           email = "drago.plecko@stat.math.ethz.ch"),
    person(given = "Ida-Fong",
           family = "Ukor",
           role = c("aut"),
           email = "ida-fong.ukor@monashhealth.org")
    )
License: GPL-3
Encoding: UTF-8
Language: en-US
URL:
    https://github.com/eth-mds/ricu,
    https://physionet.org
BugReports: https://github.com/eth-mds/ricu/issues
Depends:
    R (>= 3.4.0)
Imports:
    data.table,
    curl,
    assertthat,
    fst,
    readr,
    jsonlite,
    methods,
    stats,
    prt (>= 0.1.2),
    tibble,
    backports,
    rlang,
    vctrs,
    cli (>= 2.1.0),
    fansi,
    openssl,
    utils
Suggests:
    xml2,
    covr,
    testthat (>= 3.0.0),
    withr,
    mockthat,
    pkgload,
    mimic.demo,
    eicu.demo,
    progress,
    knitr,
    rmarkdown,
    ggplot2,
    cowplot,
    survival,
    forestmodel,
    rticles,
    kableExtra,
    units,
    pdftools,
    magick
RoxygenNote: 7.2.1
Additional_repositories: https://eth-mds.github.io/physionet-demo
VignetteBuilder: knitr
Config/testthat/edition: 3

Thanks again, I really appreciate that you are helping me!

I am now able to load the package (I think) because

library(ricu)

doesn't give me an error anymore and I can tick its box in the packages window.

However, unfortunately when I try to use the functions, I still get the same error:

> src_data_avail()
Error in metadata_fst(path, old_format) : 
  It seems the file header was damaged or incomplete

Here's the expected output. Be sure to have installed the packages commented in the first few lines

ibrary(ricu)
#> 
#> ── ricu 0.5.4 ──────────────────────────────────────────────────────────────────
#> 
#> The following data sources are configured to be attached:
#> (the environment variable `RICU_SRC_LOAD` controls this)
#> 
#> βœ– mimic: 0 of 26 tables available
#> βœ” mimic_demo: 25 of 25 tables available
#> βœ– eicu: 0 of 31 tables available
#> βœ” eicu_demo: 31 of 31 tables available
#> βœ– hirid: 0 of 5 tables available
#> βœ– aumc: 0 of 7 tables available
#> βœ– miiv: 0 of 27 tables available
#> 
#> ────────────────────────────────────────────────────────────────────────────────
# if necessary
# install.packages(
#   c("mimic.demo", "eicu.demo"),
#   repos = "https://eth-mds.github.io/physionet-demo"
# )


src_data_avail()
#>         name available tables total
#> 1      mimic     FALSE      0    26
#> 2 mimic_demo      TRUE     25    25
#> 3       eicu     FALSE      0    31
#> 4  eicu_demo      TRUE     31    31
#> 5      hirid     FALSE      0     5
#> 6       aumc     FALSE      0     7
#> 7       miiv     FALSE      0    27

Hello,

I deleted and reinstalled R and R Studio completely and now it finally works again, that was the only solution with which I had any success.

Nevertheless, many thanks for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.