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 3 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
63 changes: 34 additions & 29 deletions vignettes/tidyverse_translation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vignette: >
%\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,25 @@ knitr::opts_chunk$set(

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.
# Therefore, we introduce a logical that is `FALSE` only if all suggested
# dependencies 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 +48,7 @@ This vignette can be referred to by citing the following:

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 +93,6 @@ This vignette is largely inspired from `{dplyr}`'s [Getting started vignette](ht
</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 All @@ -97,20 +102,20 @@ efc <- head(efc)
Before we look at their *tidyverse* equivalents, we can first have a look at
`{datawizard}`'s key functions for data wrangling:

| Function | Operation |
| :---------------- | :------------------------------------------------ |
| `data_filter()` | [to select only certain observations](#filtering) |
| `data_select()` | [to select only a few variables](#selecting) |
| `data_modify()` | [to create variables or modify existing ones](#modifying) |
| `data_arrange()` | [to sort observations](#sorting) |
| `data_extract()` | [to extract a single variable](#extracting) |
| `data_rename()` | [to rename variables](#renaming) |
| `data_relocate()` | [to reorder a data frame](#relocating) |
| `data_to_long()` | [to convert data from wide to long](#reshaping) |
| `data_to_wide()` | [to convert data from long to wide](#reshaping) |
| `data_join()` | [to join two data frames](#joining) |
| `data_unite()` | [to concatenate several columns into a single one](#uniting) |
| `data_separate()` | [to separate a single column into multiple columns](#separating) |
| Function | Operation |
| :---------------- | :--------------------------------------------------------------- |
| `data_filter()` | [to select only certain observations](#filtering) |
| `data_select()` | [to select only a few variables](#selecting) |
| `data_modify()` | [to create variables or modify existing ones](#modifying) |
| `data_arrange()` | [to sort observations](#sorting) |
| `data_extract()` | [to extract a single variable](#extracting) |
| `data_rename()` | [to rename variables](#renaming) |
| `data_relocate()` | [to reorder a data frame](#relocating) |
| `data_to_long()` | [to convert data from wide to long](#reshaping) |
| `data_to_wide()` | [to convert data from long to wide](#reshaping) |
| `data_join()` | [to join two data frames](#joining) |
| `data_unite()` | [to concatenate several columns into a single one](#uniting) |
| `data_separate()` | [to separate a single column into multiple columns](#separating) |

Note that there are a few functions in `{datawizard}` that have no strict equivalent
in `{dplyr}` or `{tidyr}` (e.g `data_rotate()`), and so we won't discuss them in
Expand All @@ -124,7 +129,7 @@ Before we look at them individually, let's first have a look at the summary tabl
| :---------------- | :------------------------------------------------------------------ |
| `data_filter()` | `dplyr::filter()`, `dplyr::slice()` |
| `data_select()` | `dplyr::select()` |
| `data_modify()` | `dplyr::mutate()` |
| `data_modify()` | `dplyr::mutate()` |
| `data_arrange()` | `dplyr::arrange()` |
| `data_extract()` | `dplyr::pull()` |
| `data_rename()` | `dplyr::rename()` |
Expand All @@ -134,8 +139,8 @@ Before we look at them individually, let's first have a look at the summary tabl
| `data_join()` | `dplyr::inner_join()`, `dplyr::left_join()`, `dplyr::right_join()`, |
| | `dplyr::full_join()`, `dplyr::anti_join()`, `dplyr::semi_join()` |
| `data_peek()` | `dplyr::glimpse()` |
| `data_unite()` | `tidyr::unite()` |
| `data_separate()` | `tidyr::separate()` |
| `data_unite()` | `tidyr::unite()` |
| `data_separate()` | `tidyr::separate()` |

## Filtering {#filtering}

Expand Down
Loading