简体   繁体   English

在 R 中读取单个 *.xlsx 文件,而不使用文件名但使用 *.xlsx

[英]read a single *.xlsx file in R without the use of filename but utilizing the *.xlsx

I download an xlxs file everyday with a long unique name with dates each day.我每天下载一个 xlxs 文件,该文件有一个很长的唯一名称,每天都有日期。 I need R to read the new xlsx file saved in the directory everyday without typing the unique name everyday.我需要 R 来每天读取目录中保存的新 xlsx 文件,而无需每天输入唯一的名称。 My idea is to utilize the *.xlsx but whenever I try it, it always say the path does not exist:我的想法是利用 *.xlsx 但每当我尝试它时,它总是说路径不存在:

excel_df <- read_excel("C:/Home/User/dbd/*.xlsx")

the code above does not work上面的代码不起作用

This code says the same:这段代码也是这样说的:

base <- as.character("C:/Home/User/dbd/*.xlsx")

files <- file.info(list.files(path = base, pattern = '*.xlsx',
                              full.names = TRUE, no.. = TRUE))
daily_numebrs<-readxl::read_excel(rownames(files)[order(files$mtime)][nrow(files)])

each line of results shows the每行结果显示

...path does not exist.

The path shouldn't contain the pattern:路径不应包含模式:

path <- "C:/Home/User/dbd"
files <- list.files(path= path, full.names=T, pattern ='\\.xlsx$')
files
lapply(files, function(file) readxl::read_excel(file))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM