0

我们正在尝试将一些表数据写入文件但没有成功。

使用write.csv.

这是我们尝试的一些示例代码:

> <%
> 
> 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!!!

函数 brew 返回一个'try-error'. 返回 HTTP 响应代码 500。

如果有人可以给我们写一个简单的例子或者更正我们的代码,那就太棒了。

谢谢,

Yoni & Tsvi。

4

1 回答 1

4

为了让您的生活更轻松,请先让您的代码独立运行,然后再引入 rApache。

您看到的错误意味着write.csv无法写入您指定的位置。由于写入文件是问题的常见来源,因此您应该添加一些检查和错误处理代码以使事情更加健壮。例如,

  1. 指定绝对路径 ( path.expand) 或至少确保您知道当前工作目录的位置 ( getwd)。

  2. 检查您正在写入的目录是否存在 ( file.exists) 并且您可以写入它 ( file.access, with mode = 2)。

  3. 将您的呼叫包裹write.csv在对try或的呼叫中tryCatch

于 2011-04-15T16:05:48.003 回答