mommomonthewind
mommomonthewind

Reputation: 4640

Python 3: capture a matrix return from subprocess with Rscript

I am using subprocess to run a Rscript. The script returns a R matrix. I am using subprocess.check_output in Python and get a string. But is there a way to get directly the output matrix in Python?

Thanks

Upvotes: 1

Views: 99

Answers (1)

Emmanuel-Lin
Emmanuel-Lin

Reputation: 1943

Exchanging objects between two languages is not an easy task.

The generic solution

This solution works for all languages:

  1. You launch your script
  2. After computation you write your results in a generic format. For example .csv or .txt or .json
  3. You reload the result in the other language

Regarding R and python

There is an existing package to do that: rpy but it might be tricky to use, and some times errors are not quite explicit (because as I said, it is tricky to exchange object between two languages).

Upvotes: 1

Related Questions