Skip to content

Commit

Permalink
preserve YAML; add initial list of authors
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Dec 2, 2023
1 parent b313632 commit ae30239
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 78 deletions.
21 changes: 20 additions & 1 deletion paper/paper.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@ authors:
- name: Jim Hester
affiliation: 1
orcid: ~
- name: Michael Chirico
affiliation: 2
orcid: ~
- name: Alexander Rosenstock
affiliation: 3
orcid: ~
- name: Indrajeet Patil
orcid: 0000-0003-1995-6531
affiliation: 4
affiliations:
- index: 1
name: Netflix
output: md_document
- index: 2
name: Google
- index: 3
name: Mathematisches Institut der Heinrich-Heine-Universität Düsseldorf
- index: 4
name: Center for Humans and Machines, Max Planck Institute for Human Development, Berlin, Germany
output:
md_document:
variant: "markdown"
preserve_yaml: true
standalone: true
bibliography: paper.bib
csl: apa.csl
link-citations: yes
Expand Down
187 changes: 110 additions & 77 deletions paper/paper.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
---
title: "Static Code Analysis for R"
date: "2023-12-02"
tags: ["R", "linter", "tidyverse"]
authors:
- name: Jim Hester
affiliation: 1
orcid: ~
- name: Michael Chirico
affiliation: 2
orcid: ~
- name: Alexander Rosenstock
affiliation: 3
orcid: ~
- name: Indrajeet Patil
orcid: 0000-0003-1995-6531
affiliation: 4
affiliations:
- index: 1
name: Netflix
- index: 2
name: Google
- index: 3
name: Mathematisches Institut der Heinrich-Heine-Universität Düsseldorf
- index: 4
name: Center for Humans and Machines, Max Planck Institute for Human Development, Berlin, Germany
output:
md_document:
variant: "markdown"
preserve_yaml: true
standalone: true
bibliography: paper.bib
csl: apa.csl
link-citations: yes
---

# Statement of Need

R is an interpreted, dynamically typed programming language ([R Core
Team, 2023](#ref-base2023)). It is a popular choice for statistical
analysis and visualization, and is used by a wide range of researchers
and data scientists. The `{lintr}` package is an open-source R package
that provides static code analysis to check for a variety of common
problems related to readability, efficiency, consistency, style, etc. In
particular, it enforces the [tidyverse style
R is an interpreted, dynamically typed programming language [@base2023].
It is a popular choice for statistical analysis and visualization, and
is used by a wide range of researchers and data scientists. The
`{lintr}` package is an open-source R package that provides static code
analysis to check for a variety of common problems related to
readability, efficiency, consistency, style, etc. In particular, it
enforces the [tidyverse style
guide]((https://style.tidyverse.org/index.html)). It is designed to be
easy to use and integrate into existing workflows, and can be run from
the command line or used as part of an automated build or continuous
Expand All @@ -18,12 +54,14 @@ convenient for users to run `{lintr}` checks on their code as they work.

As of this writing, `{lintr}` offers 115 linters.

library(lintr)
``` r
library(lintr)

length(all_linters())
#> [1] 115
length(all_linters())
#> [1] 115
```

Naturally, we cant discuss all of them here. To see details about all
Naturally, we can't discuss all of them here. To see details about all
available linters, we encourage readers to see
<https://lintr.r-lib.org/dev/reference/index.html#individual-linters>.

Expand All @@ -40,77 +78,85 @@ conditional statements is error-prone, and scalar `&&` and `||`,
respectively, are to be preferred. The `vector_logic_linter()` linter
detects such problematic usages.

lint(
text = "if (x & y) 1",
linters = vector_logic_linter()
)
#> <text>:1:7: warning: [vector_logic_linter] Conditional
#> expressions require scalar logical operators (&& and
#> ||)
#> if (x & y) 1
#> ^
``` r
lint(
text = "if (x & y) 1",
linters = vector_logic_linter()
)
#> <text>:1:7: warning: [vector_logic_linter] Conditional
#> expressions require scalar logical operators (&& and
#> ||)
#> if (x & y) 1
#> ^
```

- **Efficiency**

Sometimes the users might not be aware of a more efficient way offered
by R for carrying out a computation. `{lintr}` offers linters to provide
suggestions to improve code efficiency.

lint(
text = "any(is.na(x), na.rm = TRUE)",
linters = any_is_na_linter()
)
#> <text>:1:1: warning: [any_is_na_linter] anyNA(x) is better
#> than any(is.na(x)).
#> any(is.na(x), na.rm = TRUE)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~
``` r
lint(
text = "any(is.na(x), na.rm = TRUE)",
linters = any_is_na_linter()
)
#> <text>:1:1: warning: [any_is_na_linter] anyNA(x) is better
#> than any(is.na(x)).
#> any(is.na(x), na.rm = TRUE)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~
```

- **Readability**

Coders spend significantly more time reading compared to writing code
([McConnell, 2004](#ref-mcconnell2004code)). Thus, writing readable code
makes the code more maintainable and reduces the possibility of
introducing bugs stemming from a poor understanding of the code.
[@mcconnell2004code]. Thus, writing readable code makes the code more
maintainable and reduces the possibility of introducing bugs stemming
from a poor understanding of the code.

`{lintr}` provides a number of linters that suggest more readable
alternatives. For example, `function_left_parentheses_linter()`.

lint(
text = "stats::sd (c (x, y, z))",
linters = function_left_parentheses_linter()
)
#> <text>:1:10: style: [function_left_parentheses_linter]
#> Remove spaces before the left parenthesis in a function
#> call.
#> stats::sd (c (x, y, z))
#> ^
#> <text>:1:13: style: [function_left_parentheses_linter]
#> Remove spaces before the left parenthesis in a function
#> call.
#> stats::sd (c (x, y, z))
#> ^
``` r
lint(
text = "stats::sd (c (x, y, z))",
linters = function_left_parentheses_linter()
)
#> <text>:1:10: style: [function_left_parentheses_linter]
#> Remove spaces before the left parenthesis in a function
#> call.
#> stats::sd (c (x, y, z))
#> ^
#> <text>:1:13: style: [function_left_parentheses_linter]
#> Remove spaces before the left parenthesis in a function
#> call.
#> stats::sd (c (x, y, z))
#> ^
```

- **Tidyverse style**

`{lintr}` also provides linters to enforce the style used throughout the
`{tidyverse}` ([Wickham et al., 2019](#ref-Wickham2019)) ecosystem of R
packages. This style of coding has been outlined in the tidyverse style
guide (<https://style.tidyverse.org/index.html>).

lint(
text = "1:3 %>% mean %>% as.character",
linters = pipe_call_linter()
)
#> <text>:1:9: warning: [pipe_call_linter] Use explicit calls
#> in magrittr pipes, i.e., `a %>% foo` should be `a %>%
#> foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~
#> <text>:1:18: warning: [pipe_call_linter] Use explicit calls
#> in magrittr pipes, i.e., `a %>% foo` should be `a %>%
#> foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~~~~~~~~~
`{tidyverse}` [@Wickham2019] ecosystem of R packages. This style of
coding has been outlined in the tidyverse style guide
(<https://style.tidyverse.org/index.html>).

``` r
lint(
text = "1:3 %>% mean %>% as.character",
linters = pipe_call_linter()
)
#> <text>:1:9: warning: [pipe_call_linter] Use explicit calls
#> in magrittr pipes, i.e., `a %>% foo` should be `a %>%
#> foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~
#> <text>:1:18: warning: [pipe_call_linter] Use explicit calls
#> in magrittr pipes, i.e., `a %>% foo` should be `a %>%
#> foo()`.
#> 1:3 %>% mean %>% as.character
#> ^~~~~~~~~~~~
```

# Benefits of using `{lintr}`

Expand Down Expand Up @@ -161,17 +207,4 @@ The authors declare no conflict of interest.

# Acknowledgments

# References

McConnell, S. (2004). *Code complete*. Pearson Education.

R Core Team. (2023). *R: A language and environment for statistical
computing*. R Foundation for Statistical Computing.
<https://www.R-project.org/>

Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D.,
François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M.,
Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J.,
Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to
the <span class="nocase">tidyverse</span>. *Journal of Open Source
Software*, *4*(43), 1686. <https://doi.org/10.21105/joss.01686>
# References {#references .unnumbered}

0 comments on commit ae30239

Please sign in to comment.