Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn hard-coded path into default argument (fix #305) #429

Merged
merged 1 commit into from May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions _episodes_rmd/03-loops-R.Rmd
Expand Up @@ -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)
> > }
Expand Down
6 changes: 3 additions & 3 deletions _episodes_rmd/04-cond.Rmd
Expand Up @@ -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)
}
Expand Down