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

Minor clean-up translation vignette setup #531

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Changes from 2 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
28 changes: 16 additions & 12 deletions vignettes/tidyverse_translation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%\VignetteEngine{knitr::rmarkdown}
---

```{r message=FALSE, warning=FALSE, include=FALSE, eval = TRUE}
```{r setup, message=FALSE, warning=FALSE, include=FALSE, eval = TRUE}
library(knitr)
options(knitr.kable.NA = "")
knitr::opts_chunk$set(
Expand All @@ -21,16 +21,24 @@

pkgs <- c(
"dplyr",
"datawizard",
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to check if {datawizard} is available.

"tidyr"
)
all_deps_available <- all(vapply(pkgs, requireNamespace, quietly = TRUE, FUN.VALUE = logical(1L)))

# since we explicitely put eval = TRUE for some chunks, we can't rely on
# knitr::opts_chunk$set(eval = FALSE) at the beginning of the script. So we make
# a logical that is FALSE only if deps are not installed (cf easystats/easystats#317)
evaluate_chunk <- TRUE
if (all_deps_available) {
library(datawizard)
library(dplyr)
library(tidyr)
}

can_vignette_be_evaluated <- all_deps_available && getRversion() >= "4.1.0"

if (!all(vapply(pkgs, requireNamespace, quietly = TRUE, FUN.VALUE = logical(1L))) || getRversion() < "4.1.0") {
# since we explicitly put `eval = TRUE` for some chunks, we can't rely on
# `knitr::opts_chunk$set(eval = FALSE)` at the beginning of the script. So we make
# a logical that is `FALSE` only if deps are not installed (cf easystats/easystats#317)
if (can_vignette_be_evaluated) {
evaluate_chunk <- TRUE
} else {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this. Why not put evaluate_chunk <- all_deps_available && getRversion() >= "4.1.0" and remove this if condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. No need for an extra level of indirection.

evaluate_chunk <- FALSE
}
```
Expand All @@ -39,7 +47,7 @@

Patil et al., (2022). datawizard: An R Package for Easy Data Preparation and Statistical Transformations. *Journal of Open Source Software*, *7*(78), 4684, https://doi.org/10.21105/joss.04684

```{css, echo=FALSE, eval = evaluate_chunk}
```{css, echo=FALSE, eval = TRUE}
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to eval CSS code conditionally. Doesn't hurt us if it is evaluated.

.datawizard, .datawizard > .sourceCode {
background-color: #e6e6ff;
}
Expand Down Expand Up @@ -84,10 +92,6 @@
</div>

```{r, eval = evaluate_chunk}
library(dplyr)
library(tidyr)
library(datawizard)
Copy link
Member Author

Choose a reason for hiding this comment

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

We always load all needed libraries in the setup chunk. Happy to revert this if you think this reduces readability of the vignette.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to show explicitly what packages are used so I'd like to keep this chunk (with eval=FALSE since they are loaded in setup)


data(efc)
efc <- head(efc)
```
Expand Down Expand Up @@ -147,14 +151,14 @@

```{r filter, class.source = "datawizard"}
# ---------- datawizard -----------
starwars |>

Check warning on line 154 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=154,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
data_filter(
skin_color == "light",
eye_color == "brown"
)

# or
starwars |>

Check warning on line 161 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=161,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
data_filter(
skin_color == "light" &
eye_color == "brown"
Expand All @@ -166,7 +170,7 @@

```{r, class.source = "tidyverse"}
# ---------- tidyverse -----------
starwars |>

Check warning on line 173 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=173,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
filter(
skin_color == "light",
eye_color == "brown"
Expand Down Expand Up @@ -207,7 +211,7 @@

```{r, class.source = "tidyverse"}
# ---------- tidyverse -----------
starwars |>

Check warning on line 214 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=214,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
select(hair_color, skin_color, eye_color)
```
:::
Expand Down Expand Up @@ -251,7 +255,7 @@

```{r select3, class.source = "datawizard"}
# ---------- datawizard -----------
starwars |>

Check warning on line 258 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=258,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
data_select(select = -(hair_color:eye_color))
```
:::
Expand All @@ -260,7 +264,7 @@

```{r, class.source = "tidyverse"}
# ---------- tidyverse -----------
starwars |>

Check warning on line 267 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=267,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
select(!(hair_color:eye_color))
```
:::
Expand Down Expand Up @@ -303,7 +307,7 @@

```{r select5, class.source = "datawizard"}
# ---------- datawizard -----------
starwars |>

Check warning on line 310 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=310,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
data_select(select = is.numeric)
```
:::
Expand Down Expand Up @@ -420,7 +424,7 @@

```{r, class.source = "tidyverse"}
# ---------- tidyverse -----------
starwars |>

Check warning on line 427 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=427,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
arrange(hair_color, height)
```
:::
Expand Down Expand Up @@ -467,7 +471,7 @@
:::{}
```{r extract1, class.source = "datawizard"}
# ---------- datawizard -----------
starwars |>

Check warning on line 474 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=474,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
data_extract(gender)
```
:::
Expand All @@ -476,7 +480,7 @@

```{r, class.source = "tidyverse"}
# ---------- tidyverse -----------
starwars |>

Check warning on line 483 in vignettes/tidyverse_translation.Rmd

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=vignettes/tidyverse_translation.Rmd,line=483,col=1,[one_call_pipe_linter] Avoid pipe |> for expressions with only a single call.
pull(gender)
```
:::
Expand Down
Loading