2014-10-06 152 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