2012-11-18 65 views
1

我目前使用rseve和rserve-simpler gem。如何在rails中加載和執行外部R腳本

  1. 我想加載和執行外部R腳本
  2. 我還想將數據傳遞到從將R腳本,我的Rails應用程序

任何關於如何最好地實現這方面的經驗。我不是依賴於特定的寶石/ lib目錄

問候

回答

0

我用下面的代碼

# setup the data to be used by R scripts 
r.>> "data <- c(#{out_data_points})"  

# Setup some params for plotting 
r.>> "png(file='#{Rails.root}/public#{plot_file_name}')" 
r.>> "plot_name <- '#{self.name} : #{label}'" 

# call the custom script  
r.>> "source('#{Rails.root}/app/rscripts/custom_script.r')" 

實現這一點,我通過數據變量和腳本必須設置變量的數據發送[R R可以通過rails應用程序中的逆向方法獲得。此外,圖像被髮送到一個特定的目錄名稱的軌道應用程序指定並傳遞給RScript。

相關問題