read_folder | R Documentation |
To create a list, the syntax is:
datalist <- read_folder(folder=".", read=read.delim, header=FALSE)
It returns an error if the folder does not exist.
The names of the elements of the list are the filenames.
The parameter file can be used to predefine a list of file. If file is NULL, all the files of the folder/directory are used.
read_folder(
folder = try(file.choose(), silent = TRUE),
file = NULL,
wildcard = "*.*",
read = read.delim,
...
)
folder |
Where to search for files; can be or a file path or a folder path |
file |
list of files |
wildcard |
Define which files are to be read (examples: ".", ".xls", "essai.txt"). It can be also a vector with all filenames. |
read |
Function used to read file. Ex: read.delim or read.xls from gdata package |
... |
Parameters send to the read function |
read_folder reads all files present in a folder
Return a list with the data in the files of the folder (directory for windows users)
Marc Girondot marc.girondot@gmail.com
## Not run:
library(HelpersMG)
# Read all the .csv files from the current folder/directory
contentaslist <- read_folder(folder=".", wildcard="*.csv", read=read.csv2)
# Read all the files from the current folder/directory
contentaslist <- read_folder(folder=".", wildcard="*.*", read=read.csv2)
# Read two files from the current folder/directory
files <- c("filename1.csv", "filename2.csv")
contentaslist <- read_folder(folder=".", wildcard=files, read=read.csv2)
# To concvert the list into a single dataframe:
mydf <- do.call("rbind", contentaslist)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.