fastmean optimization is not used

Open
#2,799 1 comment 0 reactions 1 assignee View on GitHub

@ben-schwen is already working on this.

Since Nov 9, 2023.

Assessment

This issue has not been assessed yet.

Description

performance

Optimization of mean to fastmean is not mentioned when using verbose=TRUE. AFAIU following call should be optimized

data.table(x=c(1:5,NA,6:9))[, mean(x, na.rm=TRUE), verbose=TRUE]
#Detected that j uses these columns: x 
#[1] 5

In the above example [.data.table processing is terminated at this point, so .optmean function doesn't run at all. https://github.com/Rdatatable/data.table/blob/65fa5c0adbab3bb900c07581a1333e7b46ca5b9c/R/data.table.R#L1403
Minor note on .optmean. Detection of na.rm argument is made as follows:

if (length(expr)==3L && identical("na",substring(names(expr)[3L], 1L, 2L)))

Thus require first two first letters of na.rm argument name, while base mean call will work just with first letter:

mean(c(1,NA,3), n=TRUE)
#[1] 2

Base R does not seems to consistent for other functions, for example sum does not partially match na.rm argument and we have to provide fully named na.rm. Still fastmean should keep consistency to mean.

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.