A R matrix to a Haskell list, with the `clipr` package

Posted on March 13, 2018 by Stéphane Laurent
Tags: R, haskell

Assume you have a matrix in R, and you want to use it in Haskell as a list. Here is a way to go.

I will take a small matrix for the illustration.

So, for Haskell, you want:

It would be very painful to do it by hands. But the clipr package is your friend. First, write the matrix in the clipboard, like this:

No we will use cat to write the output to a file.

And then, here is the content of matrix.txt:

Well, not totally perfect. But now it’s a child game to complete the output before copying it to Haskell:

Update 2018-03-29

I’ve written a function which gives a better result:

For example, matrix2list(M) generates the text file

Nothing to change manually now. Just copy-paste.