0
필자는 Python 스크립트에서 rpy2를 사용하여 호출하는 R 함수가 있습니다. R 함수는 stdout에 출력합니다; rpy2에 R 스크립트가 호출 될 때 stdout을 억제하는 매개 변수가 있습니까?rpy2에서 출력을 표준 출력으로 침묵시키는 방법은 무엇입니까?
필자는 Python 스크립트에서 rpy2를 사용하여 호출하는 R 함수가 있습니다. R 함수는 stdout에 출력합니다; rpy2에 R 스크립트가 호출 될 때 stdout을 억제하는 매개 변수가 있습니까?rpy2에서 출력을 표준 출력으로 침묵시키는 방법은 무엇입니까?
rpy2를 사용하면 터미널과의 R 자체 상호 작용을 파이썬 함수로 다시 정의 할 수 있습니다.
문서에서 다음의 예는 파이썬 목록에 stdout
출력 을 추가하는 방법을 보여줍니다 (사물의 웅대 한 계획에 제한된 유용성을하지만, 기능의 간단한 예 수) :
buf = []
def f(x):
# function that append its argument to the list 'buf'
buf.append(x)
# output from the R console will now be appended to the list 'buf'
rinterface.set_writeconsole(f)
date = rinterface.baseenv['date']
rprint = rinterface.baseenv['print']
rprint(date())
# the output is in our list (as defined in the function f above)
print(buf)
# restore default function
rinterface.set_writeconsole(rinterface.consolePrint)
을 여기에 문서가 있습니다 : http://rpy2.readthedocs.io/en/version_2.8.x/callbacks.html#console-i-o
''StringIO'를 사용하여'stdout'을 멈출 수 있습니다. 파이썬 2에서는'StringIo' 모듈에 있고 파이썬 3에서는'io' 모듈에 있습니다. – cdarke
R면에서'invisible (expression)'을 사용하여 인쇄 방법을 숨길 수 있습니다 – Shape