2

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.

henrywongkk
  • 1,840
  • 3
  • 17
  • 26
Ankit
  • 6,388
  • 8
  • 54
  • 79
  • 2
    Can you provide reproducible example? – zx8754 Mar 18 '19 at 15:32
  • 1
    Can you provide first few rows of your data? – cropgen Mar 18 '19 at 15:34
  • 1
    This gives an example and you can parse it by clicking on the "parse message" button : https://www.paymentcomponents.com/demo/mt/selectMessage/?selectedMessage=910 . It seems that items don't have a constant character length though, so I'm not sure if the parsing is straightforward. A reproducible example (with expected output) would help a lot. – moodymudskipper Mar 18 '19 at 15:58

1 Answers1

2

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
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Technophobe01
  • 8,212
  • 3
  • 32
  • 59
  • My question is for MT 910. Is there library for MT 910? – Ankit Mar 20 '19 at 20:07
  • @Ankit Compare the structure of the MT103 and MT910 messages via https://www.paymentcomponents.com/demo/mt/submit. With that in hand, my sense is that if you review the MT103 codebase will note the evolution of MT910 from MT103. i.e If you plan to code up a solution you can derive a SWIFT MT910 parser from the MT103 parser code package referenced. If you are looking for a commercial package then my sense would be to refer you to https://github.com/prowide. – Technophobe01 Mar 20 '19 at 20:54
  • @Ankit Did i address you question ref. MT 910. Can you provide more detail on what you are trying to achieve? – Technophobe01 Mar 21 '19 at 14:10
  • Although I specifically was looking for MT910 and your answer was around MT 103 but since this gives me idea to start, I am marking it. Thanks! – Ankit Mar 21 '19 at 18:47