-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -21,16 +21,24 @@ | |
|
||
pkgs <- c( | ||
"dplyr", | ||
"datawizard", | ||
"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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this. Why not put There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
``` | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -84,10 +92,6 @@ | |
</div> | ||
|
||
```{r, eval = evaluate_chunk} | ||
library(dplyr) | ||
library(tidyr) | ||
library(datawizard) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
data(efc) | ||
efc <- head(efc) | ||
``` | ||
|
@@ -147,14 +151,14 @@ | |
|
||
```{r filter, class.source = "datawizard"} | ||
# ---------- datawizard ----------- | ||
starwars |> | ||
data_filter( | ||
skin_color == "light", | ||
eye_color == "brown" | ||
) | ||
|
||
# or | ||
starwars |> | ||
data_filter( | ||
skin_color == "light" & | ||
eye_color == "brown" | ||
|
@@ -166,7 +170,7 @@ | |
|
||
```{r, class.source = "tidyverse"} | ||
# ---------- tidyverse ----------- | ||
starwars |> | ||
filter( | ||
skin_color == "light", | ||
eye_color == "brown" | ||
|
@@ -207,7 +211,7 @@ | |
|
||
```{r, class.source = "tidyverse"} | ||
# ---------- tidyverse ----------- | ||
starwars |> | ||
select(hair_color, skin_color, eye_color) | ||
``` | ||
::: | ||
|
@@ -251,7 +255,7 @@ | |
|
||
```{r select3, class.source = "datawizard"} | ||
# ---------- datawizard ----------- | ||
starwars |> | ||
data_select(select = -(hair_color:eye_color)) | ||
``` | ||
::: | ||
|
@@ -260,7 +264,7 @@ | |
|
||
```{r, class.source = "tidyverse"} | ||
# ---------- tidyverse ----------- | ||
starwars |> | ||
select(!(hair_color:eye_color)) | ||
``` | ||
::: | ||
|
@@ -303,7 +307,7 @@ | |
|
||
```{r select5, class.source = "datawizard"} | ||
# ---------- datawizard ----------- | ||
starwars |> | ||
data_select(select = is.numeric) | ||
``` | ||
::: | ||
|
@@ -420,7 +424,7 @@ | |
|
||
```{r, class.source = "tidyverse"} | ||
# ---------- tidyverse ----------- | ||
starwars |> | ||
arrange(hair_color, height) | ||
``` | ||
::: | ||
|
@@ -467,7 +471,7 @@ | |
:::{} | ||
```{r extract1, class.source = "datawizard"} | ||
# ---------- datawizard ----------- | ||
starwars |> | ||
data_extract(gender) | ||
``` | ||
::: | ||
|
@@ -476,7 +480,7 @@ | |
|
||
```{r, class.source = "tidyverse"} | ||
# ---------- tidyverse ----------- | ||
starwars |> | ||
pull(gender) | ||
``` | ||
::: | ||
|
There was a problem hiding this comment.
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.