Reading a Swift 910 message in R

666 Views Asked by At

I have a data frame with a column including a Swift 910 message encoded as a string. I need to receive and parse the message in R.

Does R have a built-in solution for this? I don't want to reinvent the wheel unless absolutely necessary.

1

There are 1 best solutions below

4
Technophobe01 On BEST ANSWER

My recommendation would be harness the python Swift parser package via R reticulate. I am not aware of a Swift package for R.

Python Swift Parser

https://github.com/danielquinn/mt103

Usage:

from mt103 import MT103

mt103 = MT103("some-mt-103-string")
print("basic header: {}, bank op code: {}, complete message: {}".format(
    mt103.basic_header,
    mt103.text.bank_operation_code
    mt103
))

Reticulate R package

https://blog.rstudio.com/2018/03/26/reticulate-r-interface-to-python/

install.packages("reticulate")

Usage:

library(reticulate)
mt103 <- import("mt103")

Console

> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin18.5.0 (64-bit)
Running under: macOS Mojave 10.14.4

Matrix products: default
BLAS: /Users/pkjar/.Renv/versions/3.5.3/lib/R/lib/libRblas.dylib
LAPACK: /Users/pkjar/.Renv/versions/3.5.3/lib/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.3
> library(reticulate)
> mt103 <- import("mt103")
> mt103
Module(mt103)
> mt103$
mt103$date       mt103$MT103      mt103$re         mt103$Text       mt103$UserHeader