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

Style code used in examples #4098

Merged
merged 32 commits into from
Jul 1, 2020
Merged

Conversation

rjake
Copy link
Contributor

@rjake rjake commented Jun 26, 2020

Fixes #4092

This is my first PR for ggplot2. This will use the tidyverse style in the example code. I tried to check all docs. It was mentioned that a bigger audit might be done via styler at a later date and so I only picked a few types of coding style to change. If the code looked like this

 p + scale_fill_brewer(direction = -1) 

I left it be.
I only moved to new lines when there was more than one pipe present

 p + scale_fill_brewer(direction = -1) + theme_dark()

#becomes 
 p + 
  scale_fill_brewer(direction = -1) + 
  theme_dark()

when the arguments weren't indented under the parentheses, or when the line had two functions ggplot() + geom...

ggplot(mpg, aes(cty, hwy) + geom_point()

# becomes
ggplot(mpg, aes(cty, hwy) + 
  geom_point()

There were some updates that roxygen2 (dev version) made that I committed at the end

\item The default (\code{\link[scales:oob]{scales::censor()}}) replaces out of
\item The default (\code{\link[scales:censor]{scales::censor()}}) replaces out of bounds values with \code{NA}.

I also had 2 failed tests that seemed unrelated to my code changes
image

@clauswilke
Copy link
Member

The sf tests don't fail in the continuous integration runs. If tests fail for you locally you may have to update sf.

@yutannihilation
Copy link
Member

Thanks for the contribution!

There were some updates that roxygen2 (dev version) made that I committed at the end

You probably are using the older version of scales. These Rd files are now oob as of version 1.1.1, more precisely, since this commit:

r-lib/scales@e800430#diff-cf40208acff59ab6d96fa89d3c1f9a39

@yutannihilation
Copy link
Member

@rjake Could you update scales package and regenerate the docs?

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

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

Looks good to me! I added some comment on where another answer might be available, but they are just a matter of preferences so leave the questions for now.

Comment on lines +21 to +23
#' base <-
#' ggplot() +
#' xlim(-5, 5)
Copy link
Member

Choose a reason for hiding this comment

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

One question is a like break after <- should be added or not, but I think either is fine.

c.f. https://style.tidyverse.org/pipes.html#assignment-2

#'
#' # Add a text annotation
#' p +
#' geom_text() +
#' annotate("text", label = "plot mpg vs. wt", x = 2, y = 15, size = 8, colour = "red")
#' annotate(
#' "text", label = "plot mpg vs. wt",
Copy link
Member

Choose a reason for hiding this comment

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

This "text", can be placed in the same line of annotate(, but this is also fine.

Short unnamed arguments can also go on the same line as the function name, even if the whole function call spans multiple lines.
https://style.tidyverse.org/syntax.html#long-lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've noticed that Ctrl + Enter sometimes errors out at the bottom if the pattern is mismatched about code touching the parentheses or not

# fine
annotate("text", 
         label = "plot mpg vs. wt")

# fine
annotate(
  "text",
  label = "plot mpg vs. wt"
)

# not fine
annotate("text",
  label = "plot mpg vs. wt"
)

Here's an example

library(tidyverse)

mpg %>% 
  mutate(
    x1 = "ok here") %>% 
  mutate(
    x2 = "not ok") # use Ctrl + Enter in this line

image

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, thanks for the information. I hope this will be fixed on RStudio...

@yutannihilation yutannihilation merged commit 3aa2937 into tidyverse:master Jul 1, 2020
@yutannihilation
Copy link
Member

Thanks!

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.

Code style in examples hard to read in reference docs
3 participants