项目作者: thospfuller

项目描述 :
R COBOL DI (Data Integration) Package : Import COBOL CopyBook data files directly into R as properly structured data frames.
高级语言: COBOL
项目地址: git://github.com/thospfuller/rcoboldi.git
创建时间: 2020-01-14T15:46:54Z
项目社区:https://github.com/thospfuller/rcoboldi

开源协议:GNU Lesser General Public License v3.0

下载


R COBOL DI (Data Integration) Package: A package for importing COBOL CopyBook data directly into the R Project as data frames.

License LinkedIn Twitter GitHub Email Coherent Logic Limited

The RCOBOLDI Package (COBOL Data Integration Package for the R Project for Statistical Computing) is an R package that facilitates the importation of COBOL CopyBook data directly into R as properly structured data frames.

Note that not all copybook files can be converted into CSV — for example single-record type files can be converted to CSV however complicated multi-record type files will NOT map to CSV.

R COBOL Data Integration (RCOBOLDI) package examples

Example One: Install the RCOBOLDI package locally and then convert COBOL data files into data frames.

In this simple example the R COBOL Data Integration package has been installed locally and several data files are converted into data frames using the ReadCopyBookAsDataFrame function; the CobolToCSV function is also demonstrated.

This example also how includes a call to CobolToCSV.

R COBOL Data Integration (RCOBOLDI) package preconditions

The following should be executed prior to attempting to run the R script, below.

  • R version 3.6.3
  • Java 11
  • install.packages(c(“drat”, “RJSONIO”, “rJava”))

If you have trouble with rJava and Java 11 then you might need to execute the following:

R CMD javareconf

R COBOL Data Integration (RCOBOLDI) package example

The following example should work with the only change needed being the path to the files.

Test files can be found here.

  1. library(drat)
  2. drat::addRepo("thospfuller")
  3. # The following should work for Mac OSX (El Capitan) and on Linux.
  4. install.packages("RCOBOLDI")
  5. # Or install via source (for Windows users, specifically).
  6. install.packages("RCOBOLDI", type = "source")
  7. library("RCOBOLDI")
  8. RCOBOLDI::Initialize()
  9. #
  10. # Substitute the directory path below with one which points to the test files being used.
  11. #
  12. # The test files below can be found here:
  13. #
  14. # https://github.com/thospfuller/rcoboldi/tree/master/java/rcoboldi-core/src/test/resources
  15. #
  16. result <- RCOBOLDI::ReadCopyBookAsDataFrame(".../rcoboldi/java/rcoboldi-core/src/test/resources/example1/DTAR020.cbl", "/Users/thospfuller/development/projects/rcoboldi/java/rcoboldi-core/src/test/resources/example1/DTAR020.bin", "Fixed Length Binary", "cp037")
  17. head(result)
  18. result <- RCOBOLDI::ReadCopyBookAsDataFrame(".../rcoboldi/java/rcoboldi-core/src/test/resources/example2/DTAR107.cbl", "/Users/thospfuller/development/projects/rcoboldi/java/rcoboldi-core/src/test/resources/example2/DTAR107.bin", "Fixed Length Binary", "cp037")
  19. head(result)
  20. result <- RCOBOLDI::ReadCopyBookAsDataFrame(".../rcoboldi/java/rcoboldi-core/src/test/resources/example3/AmsLocation.cbl", "/Users/thospfuller/development/projects/rcoboldi/java/rcoboldi-core/src/test/resources/example3/Ams_LocDownload_20041228.txt", "Text", "cp1252")
  21. cobrix_test1_result <- RCOBOLDI::ReadCopyBookAsDataFrame(".../rcoboldi-gh/rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_copybook.cob", "/Users/thospfuller/development/projects/rcoboldi-gh/rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_example.bin", "**TBD**", "**TBD**")
  22. head(cobrix_test1_result)
  23. result <- RCOBOLDI::ReadCopyBookAsDataFrame(".../rcoboldi-gh/rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_copybook.cob", "/Users/thospfuller/development/projects/rcoboldi-gh/rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_example.bin", "Fixed Length Binary", "cp037")
  24. #
  25. # The following line will convert the absaoss_cobrix_test1 data file into a CSV file.
  26. #
  27. RCOBOLDI::CobolToCSV("-I .../rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_example.bin -C .../rcoboldi/java/rcoboldi-core/src/test/resources/example4/absaoss_cobrix_test1_copybook.cob -FS Fixed_Length -IC cp037 -O .../temp/absaoss_cobrix_test1.csv")

R COBOL Data Integration (RCOBOLDI) package example output

An example of the R COBOL DI (Data Integration) Package in use.


Try the R COBOL Data Integration (RCOBOLDI) package via a browser using a preconfigured Docker image available on DockerHub

Below we include two examples for working with images in Docker along with a demonstration video showing the package in action. If you just want to try the package on some test data, start here.

Using the R COBOL Data Integration (RCOBOLDI) package RStudio image on DockerHub

The RCOBOLDI Rocker/RStudio image is available on DockerHub. This image is built using dependencies which have been deployed in the thospfuller/drat repository.

The RCOBOLDI Rocker/Verse image is a complete build using source code cloned from the GitHub project repository.

The following is a fully working example based on the Rocker/RStudio image.

Pull and run the R COBOL Data Integration (RCOBOLDI) DockerHub image from the command line

docker pull thospfuller/rcoboldi-rockstar-rstudio:[latest or 1.0.3 or some other tag]

then

docker image ls

should show something like this:

  1. > REPOSITORY TAG IMAGE ID CREATED SIZE
  2. > thospfuller/rcoboldi-rockstar-rstudio 1.0.3 3f8c1c269940 37 minutes ago 2.42GB

then

docker run -d -p 8787:8787 -e PASSWORD=password --name rstudio -i -t 3f8c1c269940

Try the R COBOL Data Integration (RCOBOLDI) package from the browser

The next is to test this in R so point your browser to http://localhost:8787 and use “rstudio” and “password” to login and then execute the following:

  1. library(RCOBOLDI)
  2. RCOBOLDI::Initialize()
  3. result <- RCOBOLDI::ReadCopyBookAsDataFrame("/home/rstudio/rcoboldi/java/rcoboldi-core/src/test/resources/example1/DTAR020.cbl", "/home/rstudio/rcoboldi/java/rcoboldi-core/src/test/resources/example1/DTAR020.bin", "Fixed Length Binary", "cp037")
  4. head(result)

Building the R COBOL Data Integration (RCOBOLDI) RStudio Docker Image Locally

Step 1.) Build the R COBOL Data Integration (RCOBOLDI) (this can take up to 20 minutes).

  1. docker build -t rcoboldi/rocker-rstudio:1.0.1 https://raw.githubusercontent.com/thospfuller/rcoboldi/master/docker/rocker/rstudio/Dockerfile
  2. [some image id]

Build the Docker image from the R COBOL Data Integration package Dockerfile."

Step 2.) Run the R COBOL Data Integration (RCOBOLDI) container based on the image created in the previous step

  1. docker run -d -p 8787:8787 -e PASSWORD=password --name rstudio -i -t [some image id]
  2. [some container id]

Step 3.) Browse to http://localhost:8787 and enter the username & password combination rstudio & password.

The next three steps appear in the video.

Steps 4-7.) From the R CLI execute:

  1. #### Step 4.)
  2. library(RCOBOLDI)
  3. #### Step 5.)
  4. RCOBOLDI::Initialize()
  5. #### Step 6.)
  6. result <- RCOBOLDI::ReadCopyBookAsDataFrame("DTAR020.cbl", "DTAR020.bin", "Fixed Length Binary", "cp037")
  7. #### Step 7.)
  8. head(result)

An example of the R COBOL Data Integration Package loading a file with the inputFileStructure set to "Fixed Length Binary" and the font set to "cp037". This should work out-of-the-box with a container built from the rcoboldi:rocker-rstudio image."

YouTube

If you’re looking to load COBOL data files into the R Project for Statistical Computing then you came to the right place.

The Dockerfile in this example is based on Rocker / RStudio and will be running locally on port 8787.

Below is a video which demonstrates the R COBOL Data Integration package running in Docker.

Introduction To RCOBOLDI Data Integration Package

See Also

R COBOL Data Integration (RCOBOLDI) package logging

The Java API uses Log4J and writes files to the ~/rcoboldi-package-logs/ directory. The Log4J configuration file can be found here.

See Also