Warning when GForce functions used but also detected in calling scope

Open
#3,142 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
r
Domain
data

Research direction

First reproduce the provided data.table example with GForce and verbose=TRUE, then trace the GForce rewrite of mean calls and how definitions in the calling scope are handled. The issue is complete only after the warning behavior is agreed and covered by a regression test.

Written by the indexing model from the issue text.

Description

GForce

When GForce is enabled, simple calls using GForce functions are replaced with g-versions. If a function is defined in calling scope, I'm not sure if it is better to produce a warning since dynamic scoping does not work here as expected by unfamiliar users?

library(data.table)

data <- as.data.table(mtcars)
data[, .(disp = mean(disp)), keyby = vs]

mean <- sum
mean2 <- mean

data[, .(disp = mean(disp)), keyby = vs]
data[, .(disp = mean(disp), disp2 = mean2(disp)), keyby = vs, verbose = TRUE]
> library(data.table)
> data <- as.data.table(mtcars)
> data[, .(disp = mean(disp)), keyby = vs]
   vs     disp
1:  0 307.1500
2:  1 132.4571
> mean <- sum
> mean2 <- mean
> data[, .(disp = mean(disp)), keyby = vs]
   vs     disp
1:  0 307.1500
2:  1 132.4571
> data[, .(disp = mean(disp), disp2 = mean2(disp)), keyby = vs, verbose = TRUE]
Detected that j uses these columns: disp 
Finding groups using forderv ... 0.005sec 
Finding group sizes from the positions (can be avoided to save RAM) ... 0.000sec 
lapply optimization is on, j unchanged as 'list(mean(disp), mean2(disp))'
GForce is on, left j unchanged
Old mean optimization changed j from 'list(mean(disp), mean2(disp))' to 'list(.External(Cfastmean, disp, FALSE), mean2(disp))'
Making each group and running j (GForce FALSE) ... 
  collecting discontiguous groups took 0.000s for 2 groups
  eval(j) took 0.000s for 2 calls
0.000sec 
   vs     disp  disp2
1:  0 307.1500 5528.7
2:  1 132.4571 1854.4
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.