Calling R script from python using rpy2

后端 未结 1 1766
梦毁少年i
梦毁少年i 2020-12-04 15:58

I\'m very new to rpy2, as well as R.

I basically have a R script, script.R, which contains functions, such as rfunc(folder). It is located in the same directory as m

相关标签:
1条回答
  • 2020-12-04 16:28

    source is a r function, which runs a r source file. Therefore in rpy2, we have two ways to call it, either:

    import rpy2.robjects as robjects
    r = robjects.r
    r['source']('script.R')
    

    or

    import rpy2.robjects as robjects
    r = robjects.r
    r.source('script.R')
    

    r[r.source("script.R")] is a wrong way to do it.

    Same idea may apply to the next line.

    0 讨论(0)
提交回复
热议问题