From fe3a0286915d3dc420450049525bae763384b3f1 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 29 Dec 2025 10:10:55 -0800 Subject: [PATCH 1/2] prefer plain markdown to eval=FALSE --- vignettes/datatable-intro.Rmd | 10 +++++----- vignettes/datatable-joins.Rmd | 4 ++-- vignettes/datatable-keys-fast-subset.Rmd | 14 +++++++------- vignettes/datatable-programming.Rmd | 2 +- vignettes/datatable-reference-semantics.Rmd | 8 ++++---- ...tatable-secondary-indices-and-auto-indexing.Rmd | 4 ++-- vignettes/fr/datatable-intro.Rmd | 10 +++++----- vignettes/fr/datatable-joins.Rmd | 4 ++-- vignettes/fr/datatable-keys-fast-subset.Rmd | 14 +++++++------- vignettes/fr/datatable-reference-semantics.Rmd | 8 ++++---- ...tatable-secondary-indices-and-auto-indexing.Rmd | 4 ++-- vignettes/ru/datatable-intro.Rmd | 10 +++++----- 12 files changed, 46 insertions(+), 46 deletions(-) diff --git a/vignettes/datatable-intro.Rmd b/vignettes/datatable-intro.Rmd index 5fb3cdad4..c9392f4c5 100644 --- a/vignettes/datatable-intro.Rmd +++ b/vignettes/datatable-intro.Rmd @@ -101,7 +101,7 @@ You can also convert existing objects to a `data.table` using `setDT()` (for `da In contrast to a `data.frame`, you can do *a lot more* than just subsetting rows and selecting columns within the frame of a `data.table`, i.e., within `[ ... ]` (NB: we might also refer to writing things inside `DT[...]` as "querying `DT`", as an analogy or in relevance to SQL). To understand it we will have to first look at the *general form* of the `data.table` syntax, as shown below: -```{r eval = FALSE} +```r DT[i, j, by] ## R: i j by @@ -356,7 +356,7 @@ DF[with(DF, x > 1), ] * We can also *deselect* columns using `-` or `!`. For example: - ```{r eval = FALSE} + ```r ## not run # returns all columns except arr_delay and dep_delay @@ -367,7 +367,7 @@ DF[with(DF, x > 1), ] * From `v1.9.5+`, we can also select by specifying start and end column names, e.g., `year:day` to select the first three columns. - ```{r eval = FALSE} + ```r ## not run # returns year,month and day @@ -507,7 +507,7 @@ head(ans, 10) * Or you can also chain them vertically: - ```{r eval = FALSE} + ```r DT[ ... ][ ... ][ ... @@ -670,7 +670,7 @@ setDT(flights) The general form of `data.table` syntax is: -```{r eval = FALSE} +```r DT[i, j, by] ``` diff --git a/vignettes/datatable-joins.Rmd b/vignettes/datatable-joins.Rmd index 94167655b..a307d2e25 100644 --- a/vignettes/datatable-joins.Rmd +++ b/vignettes/datatable-joins.Rmd @@ -158,14 +158,14 @@ To use this capacity, we have 2 equivalent alternatives: - Wrapping the related columns in the base R `list` function. -```{r, eval=FALSE} +```r Products[ProductReceived, on = list(id = product_id)] ``` - Wrapping the related columns in the `list` alias `.`. -```{r, eval=FALSE} +```r Products[ProductReceived, on = .(id = product_id)] ``` diff --git a/vignettes/datatable-keys-fast-subset.Rmd b/vignettes/datatable-keys-fast-subset.Rmd index 6eee37e58..772033d8a 100644 --- a/vignettes/datatable-keys-fast-subset.Rmd +++ b/vignettes/datatable-keys-fast-subset.Rmd @@ -83,7 +83,7 @@ i.e., row names are more or less *an index* to rows of a *data.frame*. However, 2. And row names should be *unique*. - ```{r eval = FALSE} + ```r rownames(DF) = sample(LETTERS[1:5], 10, TRUE) # Warning: non-unique values when setting 'row.names': 'C', 'D' # Error in `.rowNamesDF<-`(x, value = value): duplicate 'row.names' are not allowed @@ -166,13 +166,13 @@ flights[.("JFK")] * On single column key of *character* type, you can drop the `.()` notation and use the values directly when subsetting, like subset using row names on *data.frames*. - ```{r eval = FALSE} + ```r flights["JFK"] ## same as flights[.("JFK")] ``` * We can subset any amount of values as required - ```{r eval = FALSE} + ```r flights[c("JFK", "LGA")] ## same as flights[.(c("JFK", "LGA"))] ``` @@ -261,7 +261,7 @@ flights[.("LGA", "TPA"), .(arr_delay)] * We could have returned the result by using `with = FALSE` as well. - ```{r eval = FALSE} + ```r flights[.("LGA", "TPA"), "arr_delay", with = FALSE] ``` @@ -380,14 +380,14 @@ flights[.(c("LGA", "JFK", "EWR"), "XNA"), mult = "last", nomatch = NULL] We have seen so far how we can set and use keys to subset. But what's the advantage? For example, instead of doing: -```{r eval = FALSE} +```r # key by origin,dest columns flights[.("JFK", "MIA")] ``` we could have done: -```{r eval = FALSE} +```r flights[origin == "JFK" & dest == "MIA"] ``` @@ -396,7 +396,7 @@ One advantage very likely is shorter syntax. But even more than that, *binary se As the time goes `data.table` gets new optimization and currently the latter call is automatically optimized to use *binary search*. To use slow *vector scan* key needs to be removed. -```{r eval = FALSE} +```r setkey(flights, NULL) flights[origin == "JFK" & dest == "MIA"] ``` diff --git a/vignettes/datatable-programming.Rmd b/vignettes/datatable-programming.Rmd index a4049a66f..30c2478a8 100644 --- a/vignettes/datatable-programming.Rmd +++ b/vignettes/datatable-programming.Rmd @@ -219,7 +219,7 @@ DT[, sqrt(Sepal.Length)] ``` If function name to be substituted needs to be namespace-qualified then namespace and function name can be substituted as any other symbol in the expression: -```{r substitute_fun3, result='hide', eval=FALSE} +```r DT[, ns::fun(Sepal.Length), env = list(ns="base", fun="sqrt"), verbose=TRUE] #Argument 'j' after substitute: base::sqrt(Sepal.Length) ## DT[, base::sqrt(Sepal.Length)] diff --git a/vignettes/datatable-reference-semantics.Rmd b/vignettes/datatable-reference-semantics.Rmd index edca8a7be..8b93085a1 100644 --- a/vignettes/datatable-reference-semantics.Rmd +++ b/vignettes/datatable-reference-semantics.Rmd @@ -62,7 +62,7 @@ DF When we did: -```{r eval = FALSE} +```r DF$c <- 18:13 # (1) -- replace entire column # or DF$c[DF$ID == "b"] <- 15:13 # (2) -- subassign in column 'c' @@ -89,7 +89,7 @@ It can be used in `j` in two ways: (a) The `LHS := RHS` form -```{r eval = FALSE} +```r DT[, c("colA", "colB", ...) := list(valA, valB, ...)] # when you have only one column to assign to you @@ -99,7 +99,7 @@ DT[, colA := valA] (b) The functional form -```{r eval = FALSE} +```r DT[, `:=`(colA = valA, # valA is assigned to colA colB = valB, # valB is assigned to colB ... @@ -209,7 +209,7 @@ head(flights) * When there is just one column to delete, we can drop the `c()` and double quotes and just use the column name *unquoted*, for convenience. That is: - ```{r eval = FALSE} + ```r flights[, delay := NULL] ``` diff --git a/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd b/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd index 9cb7f1cab..f4662bdb1 100644 --- a/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd +++ b/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd @@ -123,7 +123,7 @@ indices(flights) Consider the case where you would like to perform a fast key based subset on `origin` column for the value "JFK". We'd do this as: -```{r, eval = FALSE} +```r ## not run setkey(flights, origin) flights["JFK"] # or flights[.("JFK")] @@ -145,7 +145,7 @@ Unless our task involves repeated subsetting on the same column, fast key based Now if we would like to repeat the same operation but on `dest` column instead, for the value "LAX", then we have to `setkey()`, *again*. -```{r, eval = FALSE} +```r ## not run setkey(flights, dest) flights["LAX"] diff --git a/vignettes/fr/datatable-intro.Rmd b/vignettes/fr/datatable-intro.Rmd index 7dc3d138c..6f3838462 100644 --- a/vignettes/fr/datatable-intro.Rmd +++ b/vignettes/fr/datatable-intro.Rmd @@ -101,7 +101,7 @@ Vous pouvez aussi convertir des objets existants en une `data.table` en utilisan Par rapport à un `data.frame`, vous pouvez faire *beaucoup plus de choses* qu'extraire des lignes et sélectionner des colonnes dans la structure d'une `data.table`, par exemple, avec `[ ... ]` (Notez bien : nous pourrions aussi faire référence à écrire quelque chose dans `DT[...]` comme "interroger `DT`", par analogie ou similairement à SQL). Pour le comprendre il faut d'abord que nous regardions la *forme générale* de la syntaxe `data.table`, comme indiqué ci-dessous : -```{r eval = FALSE} +```r DT[i, j, by] ## R: i j by @@ -356,7 +356,7 @@ DF[with(DF, x > 1), ] * Nous pouvons également *désélectionner* des colonnes en utilisant `-` ou `!`. Par exemple : - ```{r eval = FALSE} + ```r ## pas d'exécution # renvoie toutes les colonnes sauf arr_delay et dep_delay @@ -367,7 +367,7 @@ DF[with(DF, x > 1), ] * A partir de la `v1.9.5+`, on peut aussi sélectionner en spécifiant les noms des colonnes de début et de fin, par exemple, `year:day` pour sélectionner les trois premières colonnes. - ```{r eval = FALSE} + ```r ## pas d'exécution # renvoie year,month et day @@ -507,7 +507,7 @@ head(ans, 10) * Vous pouvez également les enchaîner verticalement : - ```{r eval = FALSE} + ```r DT[ ... ][ ... ][ ... @@ -666,7 +666,7 @@ setDT(flights) La forme générale de la syntaxe de `data.table` est : -```{r eval = FALSE} +```r DT[i, j, by] ``` diff --git a/vignettes/fr/datatable-joins.Rmd b/vignettes/fr/datatable-joins.Rmd index 591decdc6..d52bf2d40 100644 --- a/vignettes/fr/datatable-joins.Rmd +++ b/vignettes/fr/datatable-joins.Rmd @@ -157,14 +157,14 @@ Pour utiliser cette possibilité, nous avons a disposition les alternatives suiv - Inclure les colonnes associées dans la fonction R de base `list` . -```{r, eval=FALSE} +```r Products[ProductReceived, on = list(id = product_id)] ``` - Inclure les colonnes associées dans l'alias `.` de `list`. -```{r, eval=FALSE} +```r Products[ProductReceived, on = .(id = product_id)] ``` diff --git a/vignettes/fr/datatable-keys-fast-subset.Rmd b/vignettes/fr/datatable-keys-fast-subset.Rmd index 1f37331ad..30e9402a4 100644 --- a/vignettes/fr/datatable-keys-fast-subset.Rmd +++ b/vignettes/fr/datatable-keys-fast-subset.Rmd @@ -86,7 +86,7 @@ autrement dit, les noms de lignes sont plus ou moins *un indice* des lignes d'un 2. Et les noms de ligne doivent être *uniques*. - ```{r eval = FALSE} + ```r rownames(DF) = sample(LETTERS[1:5], 10, TRUE) # Warning: non-unique values when setting 'row.names': 'C', 'D' @@ -170,13 +170,13 @@ flights[.("JFK")] * Pour une clé sur une seule colonne de type *caractère*, vous pouvez omettre la notation `.()` et utiliser les valeurs directement lors de l'extraction du sous-ensemble, comme si vous faisiez un sous-ensemble avec les noms de lignes dans un *data.frames*. - ```{r eval = FALSE} + ```r flights["JFK"] ## identique à flights[.("JFK")] ``` * Nous pouvons extraire autant de valeurs que nécessaire - ```{r eval = FALSE} + ```r flights[c("JFK", "LGA")] ## same as flights[.(c("JFK", "LGA"))] ``` @@ -265,7 +265,7 @@ flights[.("LGA", "TPA"), .(arr_delay)] * Nous aurions également pu renvoyer le résultat en utilisant `with = FALSE`. - ```{r eval = FALSE} + ```r flights[.("LGA", "TPA"), "arr_delay", with = FALSE] ``` @@ -384,14 +384,14 @@ flights[.(c("LGA", "JFK", "EWR"), "XNA"), mult = "last", nomatch = NULL] Nous avons vu jusqu'à présent comment définir et utiliser des clés pour extraire des sous-ensembles. Mais quel est l'avantage ? Par exemple, au lieu de faire : -```{r eval = FALSE} +```r # clé par origin,dest columns flights[.("JFK", "MIA")] ``` nous aurions pu faire : -```{r eval = FALSE} +```r flights[origin == "JFK" & dest == "MIA"] ``` @@ -399,7 +399,7 @@ Un avantage évident est d'avoir une syntaxe plus courte. Mais plus encore, *ext Au fil du temps, `data.table` bénéficie de nouvelles optimisations et actuellement, obtenir un sous-ensemble basé sur cette méthode applique automatiquement la *recherche binaire*. Afin d'utiliser la méthode lente par *balayage vectoriel*, la clé doit être supprimée. -```{r eval = FALSE} +```r setkey(flights, NULL) flights[origin == "JFK" & dest == "MIA"] ``` diff --git a/vignettes/fr/datatable-reference-semantics.Rmd b/vignettes/fr/datatable-reference-semantics.Rmd index 31ffc89b7..db0258448 100644 --- a/vignettes/fr/datatable-reference-semantics.Rmd +++ b/vignettes/fr/datatable-reference-semantics.Rmd @@ -62,7 +62,7 @@ DF Quand nous faisions : -```{r eval = FALSE} +```r DF$c <- 18:13 # (1) -- remplacer toute une colonne # ou DF$c[DF$ID == "b"] <- 15:13 # (2) -- sous-assignation dans la colonne 'c' @@ -90,7 +90,7 @@ Il peut être utilisé dans `j` de deux façons : (a) La forme `LHS := RHS` (côté gauche := côté droit) -```{r eval = FALSE} +```r DT[, c("colA", "colB", ...) := list(valA, valB, ...)] # lorsque vous n'avez qu'une seule colonne à assigner @@ -100,7 +100,7 @@ DT[, colA := valA] (b) La forme fonctionnelle -```{r eval = FALSE} +```r DT[, `:=`(colA = valA, # valA est assigné à colA colB = valB, # valB est assigné à colB ... @@ -211,7 +211,7 @@ head(flights) * Lorsqu'il n'y a qu'une seule colonne à supprimer, nous pouvons omettre le `c()` et les guillemets doubles et simplement utiliser le nom de la colonne *sans guillemets*, pour plus de commodité. C'est-à-dire : - ```{r eval = FALSE} + ```r flights[, delay := NULL] ``` diff --git a/vignettes/fr/datatable-secondary-indices-and-auto-indexing.Rmd b/vignettes/fr/datatable-secondary-indices-and-auto-indexing.Rmd index 6cde5b3d9..75e602282 100644 --- a/vignettes/fr/datatable-secondary-indices-and-auto-indexing.Rmd +++ b/vignettes/fr/datatable-secondary-indices-and-auto-indexing.Rmd @@ -123,7 +123,7 @@ indices(flights) Considérons le cas où vous voudriez effectuer un sous-ensemble basé sur une clé rapide sur la colonne `origin` pour la valeur "JFK". Nous ferions cela comme suit : -```{r, eval = FALSE} +```r ## pas exécuté setkey(flights, origin) flights["JFK"] # or flights[.("JFK")] @@ -145,7 +145,7 @@ Le calcul de l'ordre n'est pas la partie qui prend le plus de temps, puisque dat Maintenant, si nous voulons répéter la même opération mais sur la colonne `dest` à la place, pour la valeur "LAX", alors nous devons utiliser `setkey()`, *une fois de plus*. -```{r, eval = FALSE} +```r ## pas exécuté setkey(flights, dest) flights["LAX"] diff --git a/vignettes/ru/datatable-intro.Rmd b/vignettes/ru/datatable-intro.Rmd index 9ae91d994..674aaa9c1 100644 --- a/vignettes/ru/datatable-intro.Rmd +++ b/vignettes/ru/datatable-intro.Rmd @@ -148,7 +148,7 @@ class(DT$ID) «запросом к `DT`», по аналогии с SQL). Для понимания этого сначала нужно рассмотреть *общую форму* синтаксиса `data.table`, как показано ниже: -```{r eval = FALSE} +```r DT[i, j, by] ## R: i j by @@ -480,7 +480,7 @@ DF[with(DF, x > 1), ] * Мы также можем *исключить* столбцы, используя `-` или `!`. Например: - ```{r eval = FALSE} + ```r ## этот код не выполняется # вернуть все столбцы, кроме arr_delay и dep_delay @@ -493,7 +493,7 @@ DF[with(DF, x > 1), ] начальное и конечное имена столбцов, например, `year:day` для выбора первых трёх столбцов. - ```{r eval = FALSE} + ```r ## этот код не выполняется # вернуть year, month, day @@ -678,7 +678,7 @@ head(ans, 10) * Либо вы можете также соединять их вертикально: - ```{r eval = FALSE} + ```r DT[ ... ][ ... ][ ... @@ -899,7 +899,7 @@ setDT(flights) Общий синтаксис `data.table` выглядит следующим образом: -```{r eval = FALSE} +```r DT[i, j, by] ``` From 0908fa34f57477e359aca6db8de85248d2e3cfb6 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 29 Dec 2025 10:15:50 -0800 Subject: [PATCH 2/2] regression check --- .ci/linters/md/vignette_eval_false_linter.R | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .ci/linters/md/vignette_eval_false_linter.R diff --git a/.ci/linters/md/vignette_eval_false_linter.R b/.ci/linters/md/vignette_eval_false_linter.R new file mode 100644 index 000000000..b6efb5b81 --- /dev/null +++ b/.ci/linters/md/vignette_eval_false_linter.R @@ -0,0 +1,11 @@ +# ensure that ```r is preferred to 'eval=FALSE' for plain code chunks +vignette_eval_false_linter = function(md) { + if (!grepl('[.]Rmd$', md)) return(invisible()) + md = readLines(md) + bad_lines = grep(R"[eval\s*=\s*F(?:ALSE)?\b]", md) + if (!length(bad_lines)) return(invisible()) + cat(sprintf( + "Prefer '```r' chunks to ones using eval=FALSE (lines %s)", toString(bad_lines) + )) + stop('Please fix the vignette issues above') +}