apply_to_files | R Documentation |
Create a list of files that match a regex search pattern, and then apply a function to
each file. For example, run read_csv
on every .csv file in a folder.
apply_to_files(
path,
pattern,
func,
...,
recursive = FALSE,
ignorecase = TRUE,
method = "full_join"
)
path |
(Character) The path to the folder. |
pattern |
(Character) A regular expression search pattern. |
func |
(Name) The bare name of a function to execute on each file. |
... |
(...) Optional arguments that will be passed to |
recursive |
(Logical) If |
ignorecase |
(Logical) If |
method |
(Character) The method to use to merge all of the files into one
dataframe. |
Invisibly returns a single dataframe with all of the input files merged
together. If method = "row_bind",
then a new column, orig_source_file
, contains
the source file's name. The "join" methods do not have this column because the values
are mixed together.
Desi Quintans (http://www.desiquintans.com)
http://stackoverflow.com/a/24376207
# rain <- apply_to_files(path = "Raw data/Rainfall", pattern = "csv",
# func = readr::read_csv, col_types = "Tiic",
# recursive = FALSE, ignorecase = TRUE,
# method = "row_bind")
# dplyr::sample_n(rain, 5)
#> # A tibble: 5 x 5
#>
#> orig_source_file Time Tips mV Event
#> <chr> <dttm> <int> <int> <chr>
#> 1 BOW-BM-2016-01-15.csv 2015-12-17 03:58:00 0 4047 Normal
#> 2 BOW-BM-2016-01-15.csv 2016-01-03 00:27:00 2 3962 Normal
#> 3 BOW-BM-2016-01-15.csv 2015-11-27 12:06:00 0 4262 Normal
#> 4 BIL-BPA-2018-01-24.csv 2015-11-15 10:00:00 0 4378 Normal
#> 5 BOW-BM-2016-08-05.csv 2016-04-13 19:00:00 0 4447 Normal
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.