diff --git a/_episodes_rmd/03-loops-R.Rmd b/_episodes_rmd/03-loops-R.Rmd index 295f38a41..7c3db224e 100644 --- a/_episodes_rmd/03-loops-R.Rmd +++ b/_episodes_rmd/03-loops-R.Rmd @@ -348,15 +348,16 @@ Sure enough, the maxima of these data sets show exactly the same ramp as the fir > ## Using Loops to Analyze Multiple Files > -> Write a function called `analyze_all` that takes a filename pattern as its sole argument +> Write a function called `analyze_all` that takes a folder path and +> a filename pattern as its arguments > and runs `analyze` for each file whose name matches the pattern. > > > ## Solution > > ~~~ -> > analyze_all <- function(pattern) { -> > # Runs the function analyze for each file in the current working directory +> > analyze_all <- function(folder = "data", pattern) { +> > # Runs the function analyze for each file in the given folder > > # that contains the given pattern. -> > filenames <- list.files(path = "data", pattern = pattern, full.names = TRUE) +> > filenames <- list.files(path = folder, pattern = pattern, full.names = TRUE) > > for (f in filenames) { > > analyze(f) > > } diff --git a/_episodes_rmd/04-cond.Rmd b/_episodes_rmd/04-cond.Rmd index 80691c948..34d8c79a4 100644 --- a/_episodes_rmd/04-cond.Rmd +++ b/_episodes_rmd/04-cond.Rmd @@ -50,10 +50,10 @@ analyze <- function(filename) { And also built the function `analyze_all` to automate the processing of each data file: ```{r analyze_all} -analyze_all <- function(pattern) { - # Runs the function analyze for each file in the current working directory +analyze_all <- function(folder = "data", pattern) { + # Runs the function analyze for each file in the given folder # that contains the given pattern. - filenames <- list.files(path = "data", pattern = pattern, full.names = TRUE) + filenames <- list.files(path = folder, pattern = pattern, full.names = TRUE) for (f in filenames) { analyze(f) }