在 R 中读取 Swift 910 消息

Reading a Swift 910 message in R

我有一个数据框,其中有一列包含编码为字符串的 Swift 910 消息。我需要在 R 中接收和解析消息。

R 有内置的解决方案吗?除非绝对必要,否则我不想重新发明轮子。

我的建议是通过 R reticulate 利用 python Swift 解析器包。我不知道 R 的 Swift 包。

Python Swift 解析器

https://github.com/danielquinn/mt103

用法:

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
))

网纹R包

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

install.packages("reticulate")

用法:

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

控制台

> 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