Whenever I run a script importing packages with import
in RPy2 in Python, there are always some extra lines popping up in the console. I pasted in an example below. How can I suppress that behavior?
CookieJar:r cookies$ python script.py
‘tseries’ version: 0.10-24
‘tseries’ is a package for time series analysis and computational
finance.
See ‘library(help="tseries")’ for details.
Besides require(tseries, quietly = TRUE)
and using sink()
, or its Python equivalent, there is also the simple
suppressMessages( library( tseries ))
which I prefer.
You could temporarily redirect the output stream to a blackhole just before the spammy peice of code.
import sys
class Blackhole(object):
def write(self, string):
pass
stdout = sys.stdout
sys.stdout = Blackhole()
function_el_spammo()
sys.stdout = stdout
在你的R脚本中,我会预加载tseries
包(以防万一,如果它被其他一些函数/包调用)使用
require(tseries, quietly = TRUE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.