Skip to content

Clarify $ vs [, col] behavior in docs (#7369)#7381

Merged
ben-schwen merged 10 commits intomasterfrom
issue7369
Oct 25, 2025
Merged

Clarify $ vs [, col] behavior in docs (#7369)#7381
ben-schwen merged 10 commits intomasterfrom
issue7369

Conversation

@venom1204
Copy link
Contributor

closes #7369

This PR clarifies the difference between DT$col and DT[, col] when selecting columns.

  • datatable-reference-semantics.Rmd:
    Added a short section explaining that DT$col may return a reference, while DT[, col] always returns a copy. Included a minimal example.

  • datatable-faq.Rmd:
    Added a brief note and link to the semantics vignette for details.

hi @jangorecki can you please review this when you have time ,and if any improvements are needed let me know .
thank you for your time.
thanks .

@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (59f966c) to head (f685b77).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7381   +/-   ##
=======================================
  Coverage   99.12%   99.12%           
=======================================
  Files          85       85           
  Lines       16637    16637           
=======================================
  Hits        16492    16492           
  Misses        145      145           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@ben-schwen ben-schwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM. Some wording sounds unusual and too eloborate for our usual style.

This means a variable created with `$` can change if the `data.table` is modified later, which can be unexpected. A single example demonstrates this behavior and how `copy()` provides a solution:

```{r}
library(data.table)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need

venom1204 and others added 5 commits October 22, 2025 10:30
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
@jangorecki
Copy link
Member

What about DT[["a"]]

@venom1204 venom1204 requested a review from jangorecki October 22, 2025 18:18
@ben-schwen ben-schwen merged commit c26450a into master Oct 25, 2025
8 checks passed
@ben-schwen
Copy link
Member

TY!

@ben-schwen ben-schwen deleted the issue7369 branch October 25, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comparison of DT$region v DT[,region]

3 participants