Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions .ci/linters/md/vignette_eval_false_linter.R
Original file line number Diff line number Diff line change
@@ -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')
}
10 changes: 5 additions & 5 deletions vignettes/datatable-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -507,7 +507,7 @@ head(ans, 10)

* Or you can also chain them vertically:

```{r eval = FALSE}
```r
DT[ ...
][ ...
][ ...
Expand Down Expand Up @@ -670,7 +670,7 @@ setDT(flights)

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

```{r eval = FALSE}
```r
DT[i, j, by]
```

Expand Down
4 changes: 2 additions & 2 deletions vignettes/datatable-joins.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
```
Expand Down
14 changes: 7 additions & 7 deletions vignettes/datatable-keys-fast-subset.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))]
```

Expand Down Expand Up @@ -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]
```

Expand Down Expand Up @@ -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"]
```

Expand All @@ -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"]
```
Expand Down
2 changes: 1 addition & 1 deletion vignettes/datatable-programming.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions vignettes/datatable-reference-semantics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
...
Expand Down Expand Up @@ -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]
```

Expand Down
4 changes: 2 additions & 2 deletions vignettes/datatable-secondary-indices-and-auto-indexing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions vignettes/fr/datatable-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -507,7 +507,7 @@ head(ans, 10)

* Vous pouvez également les enchaîner verticalement :

```{r eval = FALSE}
```r
DT[ ...
][ ...
][ ...
Expand Down Expand Up @@ -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]
```

Expand Down
4 changes: 2 additions & 2 deletions vignettes/fr/datatable-joins.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
```
Expand Down
14 changes: 7 additions & 7 deletions vignettes/fr/datatable-keys-fast-subset.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"))]
```

Expand Down Expand Up @@ -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]
```

Expand Down Expand Up @@ -384,22 +384,22 @@ 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"]
```

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

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"]
```
Expand Down
8 changes: 4 additions & 4 deletions vignettes/fr/datatable-reference-semantics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
...
Expand Down Expand Up @@ -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]
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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"]
Expand Down
Loading
Loading