my first post in this stackoverflow! :)
I am trying to import a table (output of an R script) using Python. This would be very helpful to avoid to translate a huge script designing a complex data.table in R.
Righ now I know how to call the R script with Python using the following code:
import os
import subprocess
#Launch selected script
command = 'C:/Program Files/R/R-3.4.0/bin/x64/Rscript.exe'
path2script = 'C:/mypath/myscript.R'
cmd = [command, path2script]
a = subprocess.call(cmd)
But then I dont know how to use the table, output of the R code, using my Python script. Would you have any idea?
Many thanks
EDIT:
I tried the solution from @punter below
import subprocess
with subprocess.Popen(['/command/to/run', '/other/parameters'], stdout=subprocess.PIPE) as proc:
table = proc.stdout.read()
But then the table as a strange format like this: (it is a subset)
A\r\n COL1 COL2 COL3\r\n 1: 2015-06-17 05:19 NA <NA>\r\n 2: 2015-06-17 05:19 NA <NA>\r\n 3: 2015-06-17 05:19 NA <NA>\r\n 4: 2015-06-17 05:19 NA <NA>\r\n 5: 2015-06-17 05:19:29 NA <NA>\r\n
and when I try the code below I get all the content in the column names
s=str(table)
data = StringIO(s)
df=pd.read_csv(data)
[0 rows x 111 columns]
EDIT NUMBER 2
trying with this "ISO-8859-1" in str like str(table, "ISO-8859-1") seems to be working and I could notice that I had more than one table in my script. I am rerunning everything in a clean way I hope it will work! :)