Clarification on use of .. (dot dot)

Open Beginner friendly
#3,199 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
r
Domain
documentation

Research direction

Start with the news-page documentation quoted in the issue and compare the shown DT[,mpg], DT[,get(colname)], and DT[,..colname] examples, including their behavior with first(). Clarify the documented distinction between selecting column names and selecting column values, and ensure the examples accurately describe the expected results.

Written by the indexing model from the issue text.

Description

documentation programming

The .. feature for fetching column names stored in character vectors is documented in the news page as:

When j is a symbol prefixed with .. it will be looked up in calling scope and its value taken to be column names or numbers.

This implies that it works similarly to typing the column name directly (had it been known at the time of writing the code). However that does not seem to be the case. E.g.

DT <- data.table(mtcars)
colname <- "mpg"

Both DT[,mpg] and DT[,get(colname)] return a vector of values. But DT[,..colname] returns a data.table.

This confused me because it has implications for calling functions on the column. E.g. I attempted to use first(): both DT[,first(mpg)] and DT[,first(get(colname))] return 21. But DT[,first(..colname)] returns 'mpg', which is the column name.

If this is expected behaviour, please will the documentation clarify the use? Thank you

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.