[英]Error reading csv file using rpy2 in python
I cannot seem to be able to run the following code and get the error: 我似乎无法运行以下代码并得到错误:
rpy2.rinterface.RRuntimeError: Error in paste(r.base_dir, r.inp_file, ".csv", sep = "") :
object 'r.base_dir' not found
I get the same error even if I replace r.base_dir by base_dir. 即使我用base_dir替换r.base_dir,我也会得到同样的错误。 The code is essentially reading in a csv file using rpy2
代码实际上是使用rpy2读取csv文件
from rpy2.robjects.packages import importr
from rpy2.robjects import r
import rpy2.robjects.numpy2ri as rpyn
r.base_dir = '/Users/r/Documents/Projects/GLM/Visualize/'
r.inp_file = 'Cns'
r.out_file = 'Main.png'
r.inp_mat = r("read.table(paste(r.base_dir,r.inp_file,'.csv',sep=''), header=T, row.names=1, sep=',')")
The Python symbols are not magically visible in the R namespace. R名称空间中的Python符号并不神奇可见。
While at it you may consider calling R functions with Python arguments. 在此期间,您可以考虑使用Python参数调用R函数。 For example here:
例如这里:
from rpy2.robjects.packages import importr
from rpy2.robjects import r
import rpy2.robjects.numpy2ri as rpyn
import os
utils = importr('utils')
base_dir = '/Users/r/Documents/Projects/GLM/Visualize/'
inp_file = 'Cns'
out_file = 'Main.png'
inp_mat = utils.read_csv(os.path.join(r.base_dir,
r.inp_file +'.csv'),
header=True,
row_names=1,
sep=',')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.