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

coding styles #151

Merged
merged 14 commits into from
Mar 21, 2022
Merged

coding styles #151

merged 14 commits into from
Mar 21, 2022

Conversation

maelle
Copy link
Member

@maelle maelle commented Feb 14, 2022

No description provided.

@maelle
Copy link
Member Author

maelle commented Feb 18, 2022

@maelle
Copy link
Member Author

maelle commented Feb 21, 2022

@mpadge mentioned https://pypi.org/project/black/ could be mentioned (for Python, not R, but still interesting).

Copy link
Contributor

@cderv cderv left a comment

Choose a reason for hiding this comment

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

Nice collection of resources put together and explain.

I wrote comment in-doc as I was reading. The below could make more sense (or not) after reading those, as I have writting this after commenting in-doc.

Overall, I am thinking about this organization which is close to what you wrote:

  • What is style guide ?
    • set of rules for the better (clarity, collaboration, ...)
    • Sometime enforce by the language (indentation in python), sometime quite loose like R (where you can add a lot of spaces) and so in the latter more own style exist
  • Why does it matters ?
    • Even alone, it helps easier reading and upkeep
    • best for collaboration : proof ? Big organization have that for all language (ex: Google)
    • General resources
  • Tools are here to help
    • linters are here for this (either to show you a problem, or sometime fix it for you)
    • and Most IDE have or can use third-party linters .
    • Usually people who code already apply a default style thanks to IDE (and this is why it is important to use IDE !)
  • Coding Style for R
    • As said, a lot of them can exist due to the language.
    • Most known is from organization (tidyverse), but other orgs have their own (mlr)
    • Users can have there own preferences (Mark, Roger, Yihui, ...)
  • Tools to help styling in R
    • IDE own support (like in RStudio)
    • Initially, we had linter only: lintr - still useful
    • If you don't mind auto-fixing: styler (most generic) formatR (opinionated)
    • Can be setup for R in different tools (VSCODE plugin, EMACS, RStudio addins)
    • Some tools go further with code improvement in context (pkgcheck)
    • Coding R chunks in Rmd is also possible !
  • Being respectful of coding style when contributing
    • About etiquette and several scenarios
    • One should follow the guide but sometimes maintenaire don't mind doing cosmetic change before merging
  • Conclusion

This covers most of the content and my other ideas. Only Markdown styling needs to be place somewhere 😅

I am just sharing all this so that you can have materials to see how we could adapt (or not) the current content. It seemed easier for now that (re)writing some parts without discussion :)

Comment on lines +17 to +32
knitr::knit_hooks$set(
plot = function(x, options) {
hugoopts <- options$hugoopts
paste0(
"{{<figure src=",
'"', x, '" ',
if (!is.null(hugoopts)) {
glue::glue_collapse(
glue::glue('{names(hugoopts)}="{hugoopts}"'),
sep = " "
)
},
">}}\n"
)
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this useful for your blog only ? Or for hugodown only ?
Otherwise, maybe a good addition in blogdown

Just writing thoughts.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think neither blogdown nor hugodown have this, or maybe one of them does now 🤔 It's for taking advantages of Hugo figure shortcode. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

No I don't think they have it seems quite useful :) Maybe that worth a Feature Request or a PR in blogdown. But I'll remember and maybe I'll do it :)

content/post/2022-02-21-code-style/index.Rmd Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Show resolved Hide resolved
@maelle maelle marked this pull request as ready for review March 21, 2022 07:45
Copy link
Contributor

@cderv cderv left a comment

Choose a reason for hiding this comment

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

It looks (almost) good to me!

A few suggested tweak for your to include (or not).

Thanks for the writing about my first comments!

content/post/2022-02-21-code-style/index.md Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Show resolved Hide resolved
content/post/2022-02-21-code-style/index.Rmd Outdated Show resolved Hide resolved

For more tools helping with code improvements, refer to the [R-hub blog post "Workflow automation tools for package developers"](/2020/04/29/maintenance/) including tips on *when* to use such tools.

## A special note on ( R ) Markdown styling
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice way of placing Markdown and R Markdown together ! 😄

maelle and others added 8 commits March 21, 2022 12:43
Co-authored-by: Christophe Dervieux <christophe.dervieux@gmail.com>
Co-authored-by: Christophe Dervieux <christophe.dervieux@gmail.com>
@maelle maelle merged commit f1c33c2 into master Mar 21, 2022
@maelle maelle deleted the code-style branch March 21, 2022 12:08
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