2011-04-15 30 views
0

我們正在嘗試將一些表格數據轉換爲文件,但沒有成功。使用write.csv如何使用rapache寫入文件?

下面是我們嘗試一些示例代碼:

> <% 
> 
> X<-c(1:666) 
> 
> print(X) 
> 
> write.csv(X,"hh") 
> 
> %> 

這裏有rapache錯誤,我們不能圖:

RApache Warning/Error!!! 

Error in file(file, ifelse(append, "a", "w")) : cannot open the connection 
RApache Warning/Error!!! 

In addition: 
RApache Warning/Error!!! 

Warning messages: 
RApache Warning/Error!!! 

1: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php' 
RApache Warning/Error!!! 

2: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php' 
RApache Warning/Error!!! 

3: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/step1_5.php' 
RApache Warning/Error!!! 

4: In readLines(icon, 1) : incomplete final line found on '/var/www/brew/sampleplan/writefile.php' 
RApache Warning/Error!!! 

5: In file(file, ifelse(append, "a", "w")) : cannot open file 'hh': Permission denied 
RApache Warning/Error!!! 

功能釀造返回的'try-error'的對象。返回HTTP響應代碼500.

如果有人能給我們寫一個簡單的例子或更正我們的代碼,它將會很棒。

感謝的,

號Yoni & Tsvi。

+2

R無法寫入R正在運行的當前工作目錄。整理您的權限並重試。 – 2011-04-15 15:47:07

+2

請不要交叉郵件!你已經在RApache郵件列表上提出了同樣的問題! – aL3xa 2011-04-15 16:07:27

回答

4

爲了讓您的生活更輕鬆,首先讓自己的代碼工作,然後引入rApache。

您所看到的錯誤意味着write.csv無法寫入您指定的位置。由於寫入文件是問題的常見來源,因此您應該添加一些檢查和錯誤處理代碼以使其更加健壯。例如,

  1. 指定一個絕對路徑(path.expand),或至少確保你知道當前的工作目錄(getwd)。

  2. 檢查您正在寫入的目錄是否存在(file.exists),並且您可以寫入它(file.access,與mode = 2)。

  3. 在致電trytryCatch致電write.csv