我需要在iPython中连接pyRserve,但尝试连接时出现错误。这就是错误。
conn = pyRserve.connect()这就是我得到的:
RConnectionRefused: Connection denied, server not reachable or not accepting connections.在pyrserve手册中提供了纠正这个问题的建议,但是我不知道我需要做什么。这就是建议(注)
注意:当应该打开到Rserve的远程连接,而pyRserve无法连接到它时,Rserve很可能只侦听它自己的内部网络连接。要强制Rserve接受来自其他计算机的连接,请创建一个名为/etc/Rserv.conf的文件,并至少添加以下行: remote enable,然后重新启动Rserve。
因此,我需要知道如何在python中实现注释和连接Rserve。
谢谢大家
发布于 2016-12-03 06:29:49
在R中(使用3.3.2)
install.packages(‘Rserve’)
library(Rserve)
Rserve() # the actual server you will be calling from python运行Rserve()后,您应该会看到以下内容,表明R服务器正在运行:正在启动Rserve..."C:\Users\bkeith\Desktop\R-33~1.2\library\Rserve\libs\x64\Rserve.exe“
在Python中
import pyReserve
conn = pyRserve.connect() # the connection to R
print conn
>> <Handle to Rserve on localhost:####>一旦打印出来,你就可以开始使用库了。
别忘了关闭你的连接,要检查它你可以使用conn.isClosed:
conn.shutdown()以下是库中的一些示例:
Ex.1 -基本语法
conn.eval(‘2+4’) #basic eval
>> 6.0Ex.2 -从python到R的列表
a = [1,2,3,4] #python list
conn.r.a = a #the R variable is named a as well
print conn.r.a
>>[1,2,3,4] #the R list is now in python as wellEx.3 -R中的函数
conn.voidEval(‘two <- function(x){ x * 2}’) #declare the function
conn.eval(‘two(9)’) #use the function
>> 18.0发布于 2016-09-19 04:16:44
我之前遇到了完全相同的问题,并能够通过安装Rserve来解决它,确保您从他们的网站下载文件并运行以下代码:
R CMD INSTALL [Rserve_1.8-0.tar.gz] #put in the file name然后,在终端中运行此命令时:
R CMD Rserve应该有消息表明r处于守护进程模式,然后从那里运行conn = pyRserve.connect()应该没有问题。
https://stackoverflow.com/questions/37196056
复制相似问题