【发布时间】:2021-01-11 03:41:03
【问题描述】:
我正在使用 purrr:walk 读取多个 excel 文件,但它失败了。我有 3 个问题:
(1) 我使用list.files函数读取了一个文件夹中的excel文件列表。但返回的值也包括子文件夹。我尝试为参数 recursive= 和 include.dirs= 设置值,但没有成功。
setwd(file_path)
files<-as_tibble(list.files(file_path,recursive=F,include.dirs=F)) %>%
filter(str_detect(value,".xlsx"))
files
(2)当我使用下面这段代码时,它可以运行没有任何错误或警告信息,但没有返回数据。
###read the excel data
file_read <- function(value1) {
print(value1)
file1<-read_excel(value1,sheet=1)
}
walk(files$value,file_read)
当我使用以下内容时,它起作用了。不知道为什么。
test<-read_excel(files$value,sheet=1)
(3) Q2,其实我想创建file1到file6,假设有6个excel文件。如何动态分配数据集名称?
【问题讨论】: