【发布时间】:2020-02-02 19:34:41
【问题描述】:
我正在使用 rpy2 在 Python 中使用 R 库。该库有一个函数 prebas() 返回一个数组,其中索引为 [8] 的项目是输出。当我在 R 代码 sn-p 中将此输出写入 CSV 时,一切都按预期工作(输出是超过 200kB 的 CSV)。但是,当我返回同一个对象 (PREBASout[8]) 时,它返回一个空对象。所以,很明显,当我将该对象写入 CSV 时,文件是空的。
run_prebasso = robjects.r('''
weather <- read.csv("/home/example_inputs/weather.csv",header = T)
PAR = c(weather$PAR,weather$PAR,weather$PAR)
TAir = c(weather$TAir,weather$TAir,weather$TAir)
Precip = c(weather$Precip,weather$Precip,weather$Precip)
VPD = c(weather$VPD,weather$VPD,weather$VPD)
CO2 = c(weather$CO2,weather$CO2,weather$CO2)
DOY = c(weather$DOY,weather$DOY,weather$DOY)
library(Rprebasso)
PREBASout = prebas(nYears = 100, PAR=PAR,TAir=TAir,VPD=VPD,Precip=Precip,CO2=CO2)
write.csv(PREBASout[8],"/home/outputs/written_in_r.csv",row.names = F)
PREBASout[8]
''')
r_write_csv = robjects.r['write.csv']
r_write_csv(run_prebasso, "/home/outputs/written_in_py.csv")
这是sn-p返回的代码:
(Pdb) run_prebasso
<rpy2.rinterface.NULLType object at 0x7fc1b31e6b48> [RTYPES.NILSXP]
问题:为什么written_in_py.csv 和written_in_r.csv 不一样?
【问题讨论】: