Skip to content

Commit 8aef2be

Browse files
Update vignettes/datatable-reference-semantics.Rmd
Co-authored-by: Benjamin Schwendinger <[email protected]>
1 parent 84452da commit 8aef2be

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

vignettes/datatable-reference-semantics.Rmd

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,18 @@ A short example:
371371
```{r}
372372
DT = data.table(a = 1:3)
373373
374-
# Create three variables using the different methods
375-
x_ref = DT$a # 1. By reference with $
376-
y_cpy = DT[, a] # 2. By copy with []
377-
z_cpy = copy(DT$a) # 3. Forced copy with copy()
374+
# three ways to get the column
375+
x_ref = DT$a # may be a reference
376+
y_cpy = DT[, a] # always a copy
377+
z_cpy = copy(DT$a) # forced copy
378378
379-
# Now, modify the original data.table by reference
379+
# modify DT by reference
380380
DT[, a := a + 10L]
381381
382-
# Check the variables:
383-
x_ref
384-
#> [1] 11 12 13
385-
y_cpy
386-
#> [1] 1 2 3
387-
z_cpy
388-
#> [1] 1 2 3
382+
# observe results
383+
x_ref # may show 11 12 13
384+
y_cpy # 1 2 3
385+
z_cpy # 1 2 3
389386
```
390387

391388
To select a single column as a vector, remember:

0 commit comments

Comments
 (0)