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

fix and unify small issues #236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Naming

As well as following the general advice for [object names], strive to use verbs for function names:
As well as following the general advice for object names in @sec-objectnames, strive to use verbs for function names:
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does this reference work? I would have expected maybe [object names](syntax#sec-objectnames) instead.

Copy link
Author

Choose a reason for hiding this comment

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

I've added {#sec-objectnames} accordingly, but linking is also good


```{r}
# Good
Expand Down
5 changes: 3 additions & 2 deletions ggplot2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ If the arguments to a ggplot2 layer don't all fit on one line, put each argument

```{r}
# Good
ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
iris |>
ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
geom_point() +
labs(
x = "Sepal width, in cm",
Expand All @@ -47,7 +48,7 @@ ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
)

# Bad
ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
iris |> ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to make the only 'bad' aspect the one about arguments on a long line.

Suggested change
iris |> ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +
iris |>
ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species)) +

Copy link
Author

Choose a reason for hiding this comment

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

totally fine what you suggest

geom_point() +
labs(x = "Sepal width, in cm", y = "Sepal length, in cm", title = "Sepal length vs. width of irises")
```
Expand Down
8 changes: 4 additions & 4 deletions pipes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Use `|>` to emphasise a sequence of actions, rather than the object that the actions are being performed on.

The tidyverse has been designed to work particuarly well with the pipe, but you can use it with any code, particularly in conjunction with the `_` placeholder.
The tidyverse has been designed to work particularly well with the pipe, but you can use it with any code, particularly in conjunction with the `_` placeholder.

```{r}
strings |>
str_replace("a", "b"),
str_replace("a", "b") |>
str_replace("x", "y")

strings |>
Expand All @@ -32,12 +32,12 @@ Avoid using the pipe when:
# Good
iris |>
summarize(across(where(is.numeric), mean), .by = Species) |>
pivot_longer(-Species, names_to = "measure", values_to = "value") |>
pivot_longer(!Species, names_to = "measure", values_to = "value") |>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does - no longer work? Is it discouraged?

Copy link
Author

Choose a reason for hiding this comment

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

it works, but I feel ! would fit better since e.g. ?dplyr::select advertises ! for taking the complement of a set of variables

arrange(value)

# Bad
iris |> summarize(across(where(is.numeric), mean), .by = Species) |>
pivot_longer(-Species, names_to = "measure", values_to = "value") |>
pivot_longer(!Species, names_to = "measure", values_to = "value") |>
arrange(value)
```

Expand Down
10 changes: 5 additions & 5 deletions syntax.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Syntax

## Object names
## Object names {#sec-objectnames}

> "There are only two hard things in Computer Science: cache invalidation and
> naming things."
Expand Down Expand Up @@ -157,7 +157,7 @@ There are a few exceptions, which should never be surrounded by spaces:
x <- 1 : 10
```

* Single-sided formulas when the right-hand side is a single identifier:
* Single-sided formulas when the right-hand side is a single identifier.

```{r}
# Good
Expand All @@ -175,7 +175,7 @@ There are a few exceptions, which should never be surrounded by spaces:
)
```

Note that single-sided formulas with a complex right-hand side do need a space:
Note that single-sided formulas with a complex right-hand side do need a space.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am fine with : here and above, could you explain more?

Copy link
Author

Choose a reason for hiding this comment

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

I just thought it would be in the spirit of things to make it uniform for all consecutive bullet points


```{r}
# Good
Expand All @@ -186,7 +186,7 @@ There are a few exceptions, which should never be surrounded by spaces:
```

* When used in tidy evaluation `!!` (bang-bang) and `!!!` (bang-bang-bang)
(because have precedence equivalent to unary `-`/`+`)
(because they have precedence equivalent to unary `-`/`+`).

```{r}
# Good
Expand All @@ -198,7 +198,7 @@ There are a few exceptions, which should never be surrounded by spaces:
call(! !xyz)
```

* The help operator
* The help operator.

```{r}
# Good
Expand Down
Loading