Skip to content

Commit 7e9907f

Browse files
Prefer ```r for unevaluated code chunks to 'eval=FALSE' (#7547)
* prefer plain markdown to eval=FALSE * regression check
1 parent 291a711 commit 7e9907f

13 files changed

+57
-46
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ensure that ```r is preferred to 'eval=FALSE' for plain code chunks
2+
vignette_eval_false_linter = function(md) {
3+
if (!grepl('[.]Rmd$', md)) return(invisible())
4+
md = readLines(md)
5+
bad_lines = grep(R"[eval\s*=\s*F(?:ALSE)?\b]", md)
6+
if (!length(bad_lines)) return(invisible())
7+
cat(sprintf(
8+
"Prefer '```r' chunks to ones using eval=FALSE (lines %s)", toString(bad_lines)
9+
))
10+
stop('Please fix the vignette issues above')
11+
}

vignettes/datatable-intro.Rmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ You can also convert existing objects to a `data.table` using `setDT()` (for `da
101101
102102
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:
103103
104-
```{r eval = FALSE}
104+
```r
105105
DT[i, j, by]
106106
107107
## R: i j by
@@ -356,7 +356,7 @@ DF[with(DF, x > 1), ]
356356

357357
* We can also *deselect* columns using `-` or `!`. For example:
358358

359-
```{r eval = FALSE}
359+
```r
360360
## not run
361361

362362
# returns all columns except arr_delay and dep_delay
@@ -367,7 +367,7 @@ DF[with(DF, x > 1), ]
367367

368368
* 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.
369369

370-
```{r eval = FALSE}
370+
```r
371371
## not run
372372

373373
# returns year,month and day
@@ -507,7 +507,7 @@ head(ans, 10)
507507

508508
* Or you can also chain them vertically:
509509

510-
```{r eval = FALSE}
510+
```r
511511
DT[ ...
512512
][ ...
513513
][ ...
@@ -670,7 +670,7 @@ setDT(flights)
670670

671671
The general form of `data.table` syntax is:
672672

673-
```{r eval = FALSE}
673+
```r
674674
DT[i, j, by]
675675
```
676676

vignettes/datatable-joins.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ To use this capacity, we have 2 equivalent alternatives:
158158

159159
- Wrapping the related columns in the base R `list` function.
160160

161-
```{r, eval=FALSE}
161+
```r
162162
Products[ProductReceived,
163163
on = list(id = product_id)]
164164
```
165165

166166
- Wrapping the related columns in the `list` alias `.`.
167167

168-
```{r, eval=FALSE}
168+
```r
169169
Products[ProductReceived,
170170
on = .(id = product_id)]
171171
```

vignettes/datatable-keys-fast-subset.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ i.e., row names are more or less *an index* to rows of a *data.frame*. However,
8383

8484
2. And row names should be *unique*.
8585

86-
```{r eval = FALSE}
86+
```r
8787
rownames(DF) = sample(LETTERS[1:5], 10, TRUE)
8888
# Warning: non-unique values when setting 'row.names': 'C', 'D'
8989
# Error in `.rowNamesDF<-`(x, value = value): duplicate 'row.names' are not allowed
@@ -166,13 +166,13 @@ flights[.("JFK")]
166166

167167
* 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*.
168168

169-
```{r eval = FALSE}
169+
```r
170170
flights["JFK"] ## same as flights[.("JFK")]
171171
```
172172

173173
* We can subset any amount of values as required
174174

175-
```{r eval = FALSE}
175+
```r
176176
flights[c("JFK", "LGA")] ## same as flights[.(c("JFK", "LGA"))]
177177
```
178178

@@ -261,7 +261,7 @@ flights[.("LGA", "TPA"), .(arr_delay)]
261261

262262
* We could have returned the result by using `with = FALSE` as well.
263263

264-
```{r eval = FALSE}
264+
```r
265265
flights[.("LGA", "TPA"), "arr_delay", with = FALSE]
266266
```
267267

@@ -380,14 +380,14 @@ flights[.(c("LGA", "JFK", "EWR"), "XNA"), mult = "last", nomatch = NULL]
380380

381381
We have seen so far how we can set and use keys to subset. But what's the advantage? For example, instead of doing:
382382

383-
```{r eval = FALSE}
383+
```r
384384
# key by origin,dest columns
385385
flights[.("JFK", "MIA")]
386386
```
387387

388388
we could have done:
389389

390-
```{r eval = FALSE}
390+
```r
391391
flights[origin == "JFK" & dest == "MIA"]
392392
```
393393

@@ -396,7 +396,7 @@ One advantage very likely is shorter syntax. But even more than that, *binary se
396396
As the time goes `data.table` gets new optimization and currently the latter call is automatically optimized to use *binary search*.
397397
To use slow *vector scan* key needs to be removed.
398398

399-
```{r eval = FALSE}
399+
```r
400400
setkey(flights, NULL)
401401
flights[origin == "JFK" & dest == "MIA"]
402402
```

vignettes/datatable-programming.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ DT[, sqrt(Sepal.Length)]
219219
```
220220

221221
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:
222-
```{r substitute_fun3, result='hide', eval=FALSE}
222+
```r
223223
DT[, ns::fun(Sepal.Length), env = list(ns="base", fun="sqrt"), verbose=TRUE]
224224
#Argument 'j' after substitute: base::sqrt(Sepal.Length)
225225
## DT[, base::sqrt(Sepal.Length)]

vignettes/datatable-reference-semantics.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ DF
6262

6363
When we did:
6464

65-
```{r eval = FALSE}
65+
```r
6666
DF$c <- 18:13 # (1) -- replace entire column
6767
# or
6868
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:
8989

9090
(a) The `LHS := RHS` form
9191

92-
```{r eval = FALSE}
92+
```r
9393
DT[, c("colA", "colB", ...) := list(valA, valB, ...)]
9494

9595
# when you have only one column to assign to you
@@ -99,7 +99,7 @@ DT[, colA := valA]
9999

100100
(b) The functional form
101101

102-
```{r eval = FALSE}
102+
```r
103103
DT[, `:=`(colA = valA, # valA is assigned to colA
104104
colB = valB, # valB is assigned to colB
105105
...
@@ -209,7 +209,7 @@ head(flights)
209209

210210
* 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:
211211

212-
```{r eval = FALSE}
212+
```r
213213
flights[, delay := NULL]
214214
```
215215

vignettes/datatable-secondary-indices-and-auto-indexing.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ indices(flights)
123123

124124
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:
125125

126-
```{r, eval = FALSE}
126+
```r
127127
## not run
128128
setkey(flights, origin)
129129
flights["JFK"] # or flights[.("JFK")]
@@ -145,7 +145,7 @@ Unless our task involves repeated subsetting on the same column, fast key based
145145

146146
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*.
147147

148-
```{r, eval = FALSE}
148+
```r
149149
## not run
150150
setkey(flights, dest)
151151
flights["LAX"]

vignettes/fr/datatable-intro.Rmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Vous pouvez aussi convertir des objets existants en une `data.table` en utilisan
101101
102102
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 :
103103
104-
```{r eval = FALSE}
104+
```r
105105
DT[i, j, by]
106106
107107
## R: i j by
@@ -356,7 +356,7 @@ DF[with(DF, x > 1), ]
356356

357357
* Nous pouvons également *désélectionner* des colonnes en utilisant `-` ou `!`. Par exemple :
358358

359-
```{r eval = FALSE}
359+
```r
360360
## pas d'exécution
361361

362362
# renvoie toutes les colonnes sauf arr_delay et dep_delay
@@ -367,7 +367,7 @@ DF[with(DF, x > 1), ]
367367

368368
* 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.
369369

370-
```{r eval = FALSE}
370+
```r
371371
## pas d'exécution
372372

373373
# renvoie year,month et day
@@ -507,7 +507,7 @@ head(ans, 10)
507507

508508
* Vous pouvez également les enchaîner verticalement :
509509

510-
```{r eval = FALSE}
510+
```r
511511
DT[ ...
512512
][ ...
513513
][ ...
@@ -666,7 +666,7 @@ setDT(flights)
666666

667667
La forme générale de la syntaxe de `data.table` est :
668668

669-
```{r eval = FALSE}
669+
```r
670670
DT[i, j, by]
671671
```
672672

vignettes/fr/datatable-joins.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ Pour utiliser cette possibilité, nous avons a disposition les alternatives suiv
157157

158158
- Inclure les colonnes associées dans la fonction R de base `list` .
159159

160-
```{r, eval=FALSE}
160+
```r
161161
Products[ProductReceived,
162162
on = list(id = product_id)]
163163
```
164164

165165
- Inclure les colonnes associées dans l'alias `.` de `list`.
166166

167-
```{r, eval=FALSE}
167+
```r
168168
Products[ProductReceived,
169169
on = .(id = product_id)]
170170
```

vignettes/fr/datatable-keys-fast-subset.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ autrement dit, les noms de lignes sont plus ou moins *un indice* des lignes d'un
8686

8787
2. Et les noms de ligne doivent être *uniques*.
8888

89-
```{r eval = FALSE}
89+
```r
9090
rownames(DF) = sample(LETTERS[1:5], 10, TRUE)
9191

9292
# Warning: non-unique values when setting 'row.names': 'C', 'D'
@@ -170,13 +170,13 @@ flights[.("JFK")]
170170

171171
* 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*.
172172

173-
```{r eval = FALSE}
173+
```r
174174
flights["JFK"] ## identique à flights[.("JFK")]
175175
```
176176

177177
* Nous pouvons extraire autant de valeurs que nécessaire
178178

179-
```{r eval = FALSE}
179+
```r
180180
flights[c("JFK", "LGA")] ## same as flights[.(c("JFK", "LGA"))]
181181
```
182182

@@ -265,7 +265,7 @@ flights[.("LGA", "TPA"), .(arr_delay)]
265265

266266
* Nous aurions également pu renvoyer le résultat en utilisant `with = FALSE`.
267267

268-
```{r eval = FALSE}
268+
```r
269269
flights[.("LGA", "TPA"), "arr_delay", with = FALSE]
270270
```
271271

@@ -384,22 +384,22 @@ flights[.(c("LGA", "JFK", "EWR"), "XNA"), mult = "last", nomatch = NULL]
384384

385385
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 :
386386

387-
```{r eval = FALSE}
387+
```r
388388
# clé par origin,dest columns
389389
flights[.("JFK", "MIA")]
390390
```
391391

392392
nous aurions pu faire :
393393

394-
```{r eval = FALSE}
394+
```r
395395
flights[origin == "JFK" & dest == "MIA"]
396396
```
397397

398398
Un avantage évident est d'avoir une syntaxe plus courte. Mais plus encore, *extraire des sous-ensembles basés par recherche binaire* est **incroyablement rapide**.
399399

400400
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.
401401

402-
```{r eval = FALSE}
402+
```r
403403
setkey(flights, NULL)
404404
flights[origin == "JFK" & dest == "MIA"]
405405
```

0 commit comments

Comments
 (0)