Prepare a python string for R using rpy2

余生颓废 提交于 2019-11-29 12:59:05
hajtos

Just add the strg value to the command string:

robjects.r('''

test <- gsub("to", "",''' + strg + ''')

''')

or, by using .format:

robjects.r('''

test <- gsub("to", "",%s)

'''.format(strg))

Do note that you'll need to watch out for backslashes, see the question here

I'd recommend you to create an function, as the R function exposed by rpy2 can be called just as if it was a Python function.

my_func = robjects.r('''
function(strg) {
    test <- gsub("to", "",strg)
    test
}
''')

my_func(strg)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!