datacarpentry / R-ecology-lesson

Data Analysis and Visualization in R for Ecologists
https://datacarpentry.org/R-ecology-lesson/
Other
314 stars 508 forks source link

Grammar & Style Suggestions, Introduce forward assignment operator -> #715

Closed plhm closed 3 years ago

plhm commented 3 years ago

Hi all,

This is nitpicking given that so much awesome work has been done in this repository, but here are some notes on grammar, as well as some suggestions on style:

In Manipulating, analyzing and exporting data with tidyverse:

Grammar

Line Original Suggestion
42 and several other packages useful for data analysis and several other useful packages for data analysis
44 doing data analysis with some of the functions that come with R doing data analysis in R
48 Using R expressions in a non standard way R expressions are used in a nonstandard way
50 Hidden arguments The existence of hidden arguments
54 If we haven’t already done so, we can type install.packages("tidyverse") straight into the console. Then, to load the package type library(tidyverse) If you haven’t already done so, you can type install.packages("tidyverse") straight into the console to install the package. Then, type library(tidyverse) to load the package
72 - 73 reshape your data for plotting and use by different R functions. Sometimes reshape your data for plotting and usage by different R functions. For example, sometimes
75 Sometimes we want a data frame where Other times we want a data frame where;
182 the word "then" the word "then."
183 in the above example in the example above
186 pipe, we can pipe we can

Format

surveys_sml <- surveys %>%
  filter(weight < 5) %>%
  select(species_id, sex, weight)

surveys_sml

# Or, interchangeably 

surveys %>%
  filter(weight < 5) %>%
  select(species_id, sex, weight) -> surveys_sml

surveys_sml
Teebusch commented 3 years ago

Hi @plhm, thank you for all your suggestions! I've added some formatting to make it easier to read. I hope you don't mind.

  1. I think most of the grammar changes are uncontroversial. Would you be willing to draft a pull request for them?

  2. download link in 81-82 (links to pdf cheatsheets) - I believe it's primarily the browser that decides whether pdfs are opened in the browser or downloaded. It may be possible to override this user preference (see here and here). Changing response headers is not an option, so we'd have to modify the link:

    • Either our markdown parser supports something like [text](url){:target="_blank"}, see here
    • or we might have to use html links instead, <a href="url" target="_blank">text</a> ,see here
    • I wonder if it's worth the trouble, though? I'd suggest to accept the user's defaults for downloading pdf files and mot mess with them, since such unexpected bahavior could confuse the learners.
  3. Introducing the forward assignment operator -> - I'm a bit hesitant to use this because I think it can be a source for confusion. I understand that it adds flexibility when working interactively (and I sometimes use it, too) but It arguably makes scripts more difficult to read because forward assignment can come a bit unexpectedly. I'm worried that it would be confusing to novice R users / programmers, who might still have a fragile mental model of variable assignment at this point in the lesson. What do the other maintainers think?

em-bellis commented 3 years ago

It looked like a pull request had not been submitted yet so I created one for my carpentries instructor training checkout :). I have only implemented the grammar changes. Re: forward assignment I agree it may add a lot to the cognitive load for new users to learn it at this stage.

Teebusch commented 3 years ago

I will close this issue now. Thank you @em-bellis for the grammar fixes! I consider the other two suggestions "closed by discussion" since their hasn't been any response to my previous comment. If anyone disagrees please feel free to reopen.