Skip to content

Path as first input too #3

@CorradoLanera

Description

@CorradoLanera

Using your function with the pipe is quite complicated if the input is a path to an hl7. Here is a basic reprex:

# remotes::install_github("bransonf/hl7r")
library(hl7r)
library(withr)

hl7_file <- withr::local_file("file.hl7")

c(
  "MSH|^~`&|ECG REPORTING|ROCHESTER|ERIS|ROCHESTER|20110621050440||ORU^R01|20110621050440|P|2.1",
  "PID|||999999999||TEST^PATIENT||18450101|F",
  "OBR|||211088491|0^ADULT^ROCHECG|||20110620170631|||||||||M999999^^^^^^^RACFID||||||20110621060232||EC|F|||||||M999999^LASTNAME MD^FIRSTNAME^^^^^RACFID",
  "OBX||ST|93000.2^VENTRICULAR RATE EKG/MIN^CPT4|1|52|/SEC"
) |> 
  writeLines(hl7_file)


explicit <- parsehl7(file = hl7_file)
piped <- hl7_file |> parsehl7()
#> Error in parsehl7(hl7_file): The data specified does not appear to be valid HL7. The first line of the feed should begin with "MSH"

Created on 2022-07-13 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23 ucrt)
#>  os       Windows 10 x64 (build 22622)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       Europe/Berlin
#>  date     2022-07-13
#>  pandoc   2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  !  package     * version date (UTC) lib source
#>  P  assertthat    0.2.1   2019-03-21 [?] CRAN (R 4.2.0)
#>  P  cli           3.3.0   2022-04-25 [?] CRAN (R 4.2.0)
#>  P  crayon        1.5.1   2022-03-26 [?] CRAN (R 4.2.0)
#>  P  DBI           1.1.3   2022-06-18 [?] CRAN (R 4.2.1)
#>  PD digest        0.6.29  2021-12-01 [?] CRAN (R 4.2.0)
#>  P  dplyr         1.0.9   2022-04-28 [?] RSPM (R 4.2.0)
#>  P  ellipsis      0.3.2   2021-04-29 [?] CRAN (R 4.2.0)
#>  P  evaluate      0.15    2022-02-18 [?] CRAN (R 4.2.0)
#>  P  fansi         1.0.3   2022-03-24 [?] CRAN (R 4.2.0)
#>  PD fastmap       1.1.0   2021-01-25 [?] CRAN (R 4.2.0)
#>  P  fs            1.5.2   2021-12-08 [?] CRAN (R 4.2.0)
#>  P  generics      0.1.3   2022-07-05 [?] RSPM (R 4.2.0)
#>  PD glue          1.6.2   2022-02-24 [?] CRAN (R 4.2.0)
#>  P  highr         0.9     2021-04-16 [?] CRAN (R 4.2.0)
#>     hl7r        * 0.0.1   2022-07-13 [1] Github (bransonf/hl7r@fe51c6f)
#>  P  htmltools     0.5.2   2021-08-25 [?] CRAN (R 4.2.0)
#>  P  knitr         1.39    2022-04-26 [?] CRAN (R 4.2.0)
#>  P  lifecycle     1.0.1   2021-09-24 [?] CRAN (R 4.2.0)
#>  PD magrittr      2.0.3   2022-03-30 [?] CRAN (R 4.2.0)
#>  P  pillar        1.7.0   2022-02-01 [?] CRAN (R 4.2.0)
#>  P  pkgconfig     2.0.3   2019-09-22 [?] CRAN (R 4.2.0)
#>  PD purrr         0.3.4   2020-04-17 [?] CRAN (R 4.2.0)
#>  P  R6            2.5.1   2021-08-19 [?] CRAN (R 4.2.0)
#>  P  reprex        2.0.1   2021-08-05 [?] CRAN (R 4.2.0)
#>  P  rlang         1.0.3   2022-06-27 [?] RSPM (R 4.2.0)
#>  P  rmarkdown     2.14    2022-04-25 [?] CRAN (R 4.2.0)
#>  P  rstudioapi    0.13    2020-11-12 [?] CRAN (R 4.2.0)
#>  P  sessioninfo   1.2.2   2021-12-06 [?] CRAN (R 4.2.0)
#>  P  stringi       1.7.6   2021-11-29 [?] CRAN (R 4.2.0)
#>  P  stringr       1.4.0   2019-02-10 [?] CRAN (R 4.2.0)
#>  P  tibble        3.1.7   2022-05-03 [?] RSPM (R 4.2.0)
#>  P  tidyselect    1.1.2   2022-02-21 [?] CRAN (R 4.2.0)
#>  P  utf8          1.2.2   2021-07-24 [?] CRAN (R 4.2.0)
#>  P  vctrs         0.4.1   2022-04-13 [?] CRAN (R 4.2.0)
#>  P  withr       * 2.5.0   2022-03-03 [?] CRAN (R 4.2.0)
#>  PD xfun          0.31    2022-05-10 [?] CRAN (R 4.2.0)
#>  P  yaml          2.3.5   2022-02-21 [?] CRAN (R 4.2.0)
#> 
#>  [1] C:/Users/corrado.lanera/AppData/Local/R/cache/R/renv/library/laims.analysis-b622dba9/R-4.2/x86_64-w64-mingw32
#>  [2] C:/Program Files/R/R-4.2.1/library
#> 
#>  P ── Loaded and on-disk path mismatch.
#>  D ── DLL MD5 mismatch, broken installation.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

I have already managed to solve this by admitting both actual and a path as a first input, maintaining the second one for backward compatibility (it would not be necessary anymore, but I think it is better not to change approved APIs... anyway, if you think it could be better it can be eliminated).

My proposed solution is ready here. I'm waiting for your revision to #2 before to pull request (if you like it) because it includes all the tests written there (to guarantee back compatibility with standard input), and cannot pull request before the other one is merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions