r - 循环写入时无法打开连接
问题描述
我正在尝试遍历文件夹,读取文件,删除第二行,然后将文件写入新文件夹。我以后会做更多。我只是将其作为初始步骤运行。
我使用以下方法输入文件:
files <- list.files(path="c:/users/~/Data/Test", pattern="CRG01*", full.names=TRUE, recursive=FALSE)
然后我尝试使用 lapply。
lapply(files, function(x) {
#t <- read.table(x, header=TRUE,fill=TRUE) # load file
# apply function
#Manipulate the Power Factors Files
mydata <-read.csv(x, header = T, stringsAsFactors=FALSE)
mydata<- mydata[,1:4]
headers<- read.csv(x, header = F, nrows = 1, as.is = T, stringsAsFactors=FALSE)
headers<- headers[,1:4]
x_in <- read.csv(x, skip=2,header = F, stringsAsFactors=FALSE)
x_in<- x_in[,1:4]
colnames(x_in)= headers
# write to file
write.table(x_in, "c:/Users/~/Data/Test/Output", sep="\t",
row.names=FALSE, col.names=TRUE)
})
当我运行它时,我得到以下错误。
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
起初我以为它与管理员权限有关,但我被允许以管理员身份运行作为测试并得到相同的错误。现在我不知道原因是什么。
谢谢是提前!
解决方案
推荐阅读
- python - Tkinter使用for循环将条目数据保存在excel文件中
- java - 如何使用 Java 检查 Selenium 中显示的日期
- visual-studio-code - 在 VS Code 中向 gdb 发送消息
- javascript - 在谷歌标签管理器服务器端准备一个输入表,作为 API 请求正文的一部分发送
- knitr - knitr 内联代码“message = false”不起作用
- unity3d - 如何调整/拉伸世界空间 UI?
- python - 使用 Pandas 创建多级列
- amazon-web-services - 函数返回 null 作为响应
- docker - 覆盖父 Docker 参数
- matlab - 如何绘制分段函数(MATLAB)?