Executing an R script in python via subprocess.Popen

前端 未结 5 545
逝去的感伤
逝去的感伤 2021-01-20 23:25

When I execute the script in R, it is:

$ R --vanilla --args test_matrix.csv < hierarchical_clustering.R > out.txt

In Python, it works if

5条回答
  •  广开言路
    2021-01-21 00:14

    You never actually execute it fully ^^ try the following

    process = subprocess.Popen(['R', '--vanilla', '--args', '\\%s_DM_Instances_R.csv\\' % output_filename, '<', '/home/kevin/AV-labels/Results/R/hierarchical_clustering.R'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True) 
    process.communicate()#[0] is stdout
    

提交回复
热议问题