我正在尝试运行rstanarm库的GLM函数。我使用rpy2库将python与R包连接起来。代码如下:
glm_post = rstanarm.stan_glm(formula, data=r_dataframe, prior=my_prior,iter=niter, chains=nchains, cores=cores)
但是我在GCP AI笔记本中得到这个错误:
/opt/conda/lib/python3.7/site-packages/rpy2/robjects/functions.py in __call__(self, *args, **kwargs)
197 kwargs[r_k] = v
198 return (super(SignatureTranslatedFunction, self)
--> 199 .__call__(*args, **kwargs))
200
201
/opt/conda/lib/python3.7/site-packages/rpy2/robjects/functions.py in __call__(self, *args, **kwargs)
123 else:
124 new_kwargs[k] = conversion.py2rpy(v)
--> 125 res = super(Function, self).__call__(*new_args, **new_kwargs)
126 res = conversion.rpy2py(res)
127 return res
/opt/conda/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs)
43 def _cdata_res_to_rinterface(function):
44 def _(*args, **kwargs):
---> 45 cdata = function(*args, **kwargs)
46 # TODO: test cdata is of the expected CType
47 return _cdata_to_rinterface(cdata)
/opt/conda/lib/python3.7/site-packages/rpy2/rinterface.py in __call__(self, *args, **kwargs)
675 )
676 if error_occured[0]:
--> 677 raise embedded.RRuntimeError(_rinterface._geterrmessage())
678 return res
679
RRuntimeError: Error in utils::browseURL(paste0("file://", sinkfile_html)) :
'browser' must be a non-empty character string
browseURL()
是一个R函数,试图打开web浏览器以显示URL上的内容。GCP AI笔记本运行在云上,它运行的系统可能没有设置web浏览器。
你需要找到一种方法来调用R函数stan_glm()
,而不需要web浏览器。
通过在env.sh文件中添加这一行,我能够绕过browseURL错误。
export R_BROWSER="false"