readDir | R Documentation |
Read in all of the files in a given directory
readDir(dir_v, files_v = NULL, pattern_v = NULL, names_v = NULL)
dir_v |
Path to directory containing files that should be read in |
files_v |
Vector containing the files within dir_v to read. See details for more info. |
pattern_v |
Regex pattern to search for files within dir_v to read. See details for more info. |
names_v |
Vector containing names to assign to each element. If blank, will use file name minus extension. |
There are multiple ways to determine which files will be read. First, files_v will be checked. If this argument has been specified, then these are the files that will be read in. If it is blank (NA), then pattern_v will be checked. If this has been specified, then it will be used to find matching files. If both files_v and pattern_v are blank, then all of the files in the directory will be read.
List of data.tables
# Make directory called "~/Desktop/readDirTest"
write.table(matrix(1:100, nrow = 2), file = "~/Desktop/readDirTest/A.txt", row.names = F, quote = F, sep = '\t')
write.table(matrix(1:100, nrow = 10), file = "~/Desktop/readDirTest/B.txt", row.names = F, quote = F, sep = '\t')
write.table(matrix(1:100, nrow = 20), file = "~/Desktop/readDirTest/A.csv", row.names = F, quote = F, sep = ',')
readDir(dir_v = "~/Desktop/readDirTest)
readDir(dir_v = "~/Desktop/readDirTest, names_v = c("one", "two", "three))
readDir(dir_v = "~/Desktop/readDirTest, files_v = c("B.txt", "A.csv"))
readDir(dir_v = "~/Desktop/readDirTest, pattern_v = "*.txt")
readDir(dir_v = "~/Desktop/readDirTest, pattern_v = "A.*")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.