lapply 在 R 中,无法打开连接?

Posted

技术标签:

【中文标题】lapply 在 R 中,无法打开连接?【英文标题】:lapply in R , cannot open connection? 【发布时间】:2018-03-27 21:03:22 【问题描述】:

这是我的代码:

library(DBI)
library(proto)
library(chron)
library(RSQLite)
library(sqldf)

setwd("C:/Users/Rachael/Desktop")# set directory to desktop

files = list.files(path = "C:/Users/Rachael/Documents" ,pattern = ".csv")

(files) # show filenames in the working directory

rdf=lapply(files, read.csv) # files are loaded into rdf

这是错误信息

(files) # show filenames in the working directory
[1] "PIR.csv"  "TWTR.csv"
rdf=lapply(files, read.csv) # files are loaded into rdf

文件中的错误(文件,“rt”):无法打开连接 另外:警告信息: 在文件中(文件,“rt”):无法打开文件'PIR.csv':没有这样的文件或目录

“无法打开连接”是什么意思?当我显示我的文件时也发现了 PIR.csv,那么为什么稍后会出现没有这样的文件呢?

【问题讨论】:

您将工作目录设置为Desktop,但文件位于Documents 您从setwd...Desktop,然后从...Documents 获取文件列表。因此,您试图从Desktop 获取PIR.CSV(位于Documents),这就是错误的原因。尝试将full.names = TRUE 添加到list.files 【参考方案1】:

使用getwd() 命令查看您的文件路径。很多时候,人们忘记了read.csv 命令是基于当前工作目录读取的。将来解决此问题的一个好方法是生成一个绝对文件路径名。

【讨论】:

以上是关于lapply 在 R 中,无法打开连接?的主要内容,如果未能解决你的问题,请参考以下文章

R ftpUplad 错误:无法打开连接

tm readPDF:文件错误(con,“r”):无法打开连接

文件中的错误(文件,“rt”):无法打开连接[重复]

如何在 R 的 lapply() 中引用正在操作的行

F0520005: 无法打开源文件“r_bsp_config.h”

如何解决Win10系统无法使用VPN