Skip to content

[WIP] Module on "Workflow and piping" - #8

Draft
etiennebacher wants to merge 10 commits into
mainfrom
module-workflow-piping
Draft

[WIP] Module on "Workflow and piping"#8
etiennebacher wants to merge 10 commits into
mainfrom
module-workflow-piping

Conversation

@etiennebacher

@etiennebacher etiennebacher commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

@github-actions

Copy link
Copy Markdown

@willgearty willgearty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some preliminary comments and thoughts. Let me know if you have any questions.

Comment thread workflow_piping/index.qmd
# Same name gets overwritten
res <- head(mtcars, 10)
res <- subset(res, cyl >= 6)
res <- sort_by(res, ~ am)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_by is a relatively new function (I'm not sure I knew it existed). Maybe a more classic res[order(res$am), ] would be better (or could be used as an even more "classical" approach)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do leave it, we may want to devote some time to explain the formula syntax (I don't think a lot of beginners are familiar with it)

@etiennebacher etiennebacher Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced in R 4.4 (two years ago) and I had chosen it because it's easy to read and fits very nicely in the various syntaxes presented here. Using res[order(res$am), ] would be annoying in the case of nested calls and when we show the example with the pipe below.

I agree the ~ might be slightly unexpected but I still think the intent of the function is clear without devoting some space to explain ~.

@willgearty willgearty Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you might be surprised to hear how old some people's installed R versions are...But I do agree it reads well. In general for these modules, I think it's better to include more detail rather than less. In this case, the formula format seems to be the intended way for sort_by(), so it's probably fine.

Related but not for this PR: I wonder if we could have functions link to reference docs like in pkgdown...

Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd
Comment thread workflow_piping/index.qmd Outdated

## Example where we don't use the pipe

Let's say we want to keep the first 10 rows in the `mtcars` data, then keep the observations where `cyl >= 6`, and finally sort the remaining data by the `am` column.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this a bulleted list of actions to be taken. Then it will be easy to track how each bullet translates into each line of code below

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could even have the three lines be comments in the code, for example:

# keep the first 10 rows in the `mtcars` data
res <- head(mtcars, 10)
# keep the observations where `cyl >= 6`
res <- subset(res, cyl >= 6)
# sort the remaining data by the `am` column
res <- sort_by(res, ~ am)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could even envision a nice slide setup where the code comes in one-by-one underneath the comments

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to a bulleted list but I think the code is simple enough to avoid comments on each line (also because we repeat the same code several times with different syntaxes, so it's better if we can keep it "clean" without comments IMO).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this comes down to personal preference. It's probably fine as-is for now.

Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd
Comment thread workflow_piping/index.qmd
Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd Outdated
Comment thread workflow_piping/index.qmd
# Same name gets overwritten
res <- head(mtcars, 10)
res <- subset(res, cyl >= 6)
res <- sort_by(res, ~ am)

@willgearty willgearty Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you might be surprised to hear how old some people's installed R versions are...But I do agree it reads well. In general for these modules, I think it's better to include more detail rather than less. In this case, the formula format seems to be the intended way for sort_by(), so it's probably fine.

Related but not for this PR: I wonder if we could have functions link to reference docs like in pkgdown...

Comment thread workflow_piping/index.qmd Outdated

## Example where we don't use the pipe

Let's say we want to keep the first 10 rows in the `mtcars` data, then keep the observations where `cyl >= 6`, and finally sort the remaining data by the `am` column.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this comes down to personal preference. It's probably fine as-is for now.

etiennebacher and others added 2 commits August 27, 2026 14:37
Co-authored-by: William Gearty <willgearty@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants