2014-10-06 144 views
11

我在Mac和Ubuntu上都尝试过很多选项。 我读了Rserve文档如何优雅地关闭Rserve?

http://rforge.net/Rserve/doc.html 

并为Rserve和RSclient包:

http://cran.r-project.org/web/packages/RSclient/RSclient.pdf

http://cran.r-project.org/web/packages/Rserve/Rserve.pdf

我无法弄清楚什么是开了正确的工作流程/关闭在Rserve内部进行连接并优雅地关闭Rserve。例如,在Ubuntu中,我使用./config --enable-R-shlib(遵循Rserve文档)从源代码安装了R,并在/etc/Rserve.conf中添加了“控制启用”行。

在一个Ubuntu终端:

library(Rserve) 
library(RSclient) 
Rserve() 
c<-RS.connect() 
C## this is an Rserve QAP1 connection 

## Trying to shutdown the server 
RSshutdown(c) 
Error in writeBin(as.integer....): invalid connection 

RS.server.shutdown(c) 
Error in RS.server.shutdown(c): command failed with satus code 0x4e: no control line present (control commands disabled or server shutdown) 

我可以,但是,关闭连接:

RS.close(c) 
>NULL 
C## Closed Rserve connection 

关闭连接后,我也尝试的选项(也试图与参数 'c' 的,即使连接关闭):

RS.server.shutdown() 
RSshutdown() 

所以,我的问题是:

1-如何优雅地关闭Rserve?

2- Can Rserve可以在没有RSclient的情况下使用吗?

我也看了

How to Shutdown Rserve(), running in DEBUG

但问题是指在调试模式,也没有得到解决。 (我没有足够的信誉来评论/询问关机是否在非调试模式下工作)。

在又看了:

how to connect to Rserve with an R client

非常感谢!

回答

15

加载Rserve和RSclient包,然后连接到实例。

> library(Rserve) 
> library(RSclient) 

> Rserve(port = 6311, debug = FALSE) 
> Rserve(port = 6312, debug = TRUE) 

Starting Rserve... 
"C:\..\Rserve.exe" --RS-port 6311 
Starting Rserve... 
"C:\..\Rserve_d.exe" --RS-port 6312 

> rsc <- RSconnect(port = 6311) 
> rscd <- RSconnect(port = 6312) 

看起来他们正在运行...

> system('tasklist /FI "IMAGENAME eq Rserve.exe"') 
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"') 

Image Name      PID Session Name  Session# Mem Usage 
========================= ======== ================ =========== ============ 
Rserve.exe     8600 Console     1  39,312 K 
Rserve_d.exe     12652 Console     1  39,324 K 

让我们关闭“时间了。

> RSshutdown(rsc) 
> RSshutdown(rscd) 

而且他们已经走了。

> system('tasklist /FI "IMAGENAME eq Rserve.exe"') 
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"') 

INFO: No tasks are running which match the specified criteria. 

Rserve可以通过指定参数和/或配置脚本启动它使用W/O RSclient。然后您可以从其他程序(如Tableau)或您自己的代码连接到它。RSclient提供了一种指令/数据从R.

的一个实例传递给Rserve

希望这有助于:)

+0

谢谢!所以,如果我理解正确,为了将R进程与Rserve实例连接起来,我必须使用RSclient,对吗?我还需要在Rserve中指定“args”命令(否则会出现致命错误),并且在使用debug = TRUE时,命令行会一直等待,并以“错误:无法与R会话建立连接”结束。因此,使用mac,只有debug = F选项似乎可以工作,并且我使用了system('ps aux | grep Rserve')[这会打开2个连接,并带有两个不同的ID ..]。非常感谢!! – user3570398 2014-10-17 19:08:09

+0

这适用于Rserve(port = 6311,debug = FALSE,args =“ - no-save”)。谢谢! – user3570398 2014-10-17 19:16:10

4

在Windows系统上,如果你想关闭一个RServe例如,你可以使用system功能在R关闭它。 例如在R

library(Rserve) 
Rserve() # run without any arguments or ports specified 
system('tasklist /FI "IMAGENAME eq Rserve.exe"') # run this to see RServe instances and their PIDs 
system('TASKKILL /PID {yourPID} /F') # run this to kill off the RServe instance with your selected PID 

如果您有与PID正确关闭您的RServe情况下,会出现以下消息:

SUCCESS: The process with PID xxxx has been terminated.

您可以检查RServe实例已经进入关闭

system('tasklist /FI "IMAGENAME eq Rserve.exe"')

再次。如果正在运行的所有多无RServe情况下,你会得到的消息

INFO: No tasks are running which match the specified criteria.

更多的帮助和信息在这个题目可以this related question可见。

请注意,早先回答中提到的'RSClient'方法比这个更加简单和容易,但无论如何,对于那些不知道如何阻止它的人开始RServe