【发布时间】:2019-10-29 16:01:30
【问题描述】:
我有一个目录,里面有多个子目录,我确实想列出子目录,然后让用户选择他想在其中读取文件的子目录。
我希望在代码继续读取里面的文件之前使用索引来输入他的选择。这是我试图列出父目录中的所有子目录的内容,但我被困在如何在读取其中的文件之前使用用户原始输入来选择子目录:
path = setwd("path to parent directory")
sub_dirs <- list.dirs(path, full.names = TRUE, recursive = TRUE)
#User raw input to be used here before listing files within
.....
#list all files
files <- dir(path, pattern = '\\.csv', full.names = FALSE)
#read files
tables <- lapply(files, read.csv)
预期的输出是一个代码,我可以在其中列出父目录中的子目录,然后允许用户输入他想要读取其中文件的子目录的索引。然后在用户输入之后,代码继续列出里面的 csv 文件,然后读取文件。
【问题讨论】:
标签: r