Title: | Translating Coding Statements using get() and eval() for Improved Run-Time Coding Efficiency |
---|---|
Description: | The getDTeval() function facilitates the translation of the original coding statement to an optimized form for improved runtime efficiency without compromising on the programmatic coding design. The function can either provide a translation of the coding statement, directly evaluate the translation to return a coding result, or provide both of these outputs. |
Authors: | David Shilane [aut], Mayur Bansal [ctb, cre], Anderson Nelson [ctb], Caffrey Lee [ctb], Zichen Huang [ctb] |
Maintainer: | Mayur Bansal <[email protected]> |
License: | GPL-3 |
Version: | 0.0.2 |
Built: | 2025-02-08 04:23:02 UTC |
Source: | https://github.com/cran/getDTeval |
Performs a benchmarking experiment for data.table coding statements that use get() or eval() for programmatic designs. The a) original statement is compared to b) passing the original statement through getDTeval and also to c) an optimized coding statement. The results can demonstrate the overall improvement of using the coding translations offered by getDTeval()
benchmark.getDTeval( the.statement, times = 30, seed = 47, envir = .GlobalEnv, ... )
benchmark.getDTeval( the.statement, times = 30, seed = 47, envir = .GlobalEnv, ... )
the.statement |
refers to the original coding statement which needs to be translated to an optimized form. This value may be entered as either a character value or as an expression. |
times |
The number of iterations to run the benchmarking experiment |
seed |
an integer value specifying the seed of the pseudorandom number generator. |
envir |
The environment in which the calculation takes place, with the global environment .GlobalEnv set as the default. |
... |
provision for additonal arguments |
#Benchmarking runtime performances in calculating mean age dat<-formulaic::snack.dat age.name<-'Age' benchmark.getDTeval(the.statement = "dat[,.(mean_age=mean(get(age.name)))]", times = 5, seed = 10)
#Benchmarking runtime performances in calculating mean age dat<-formulaic::snack.dat age.name<-'Age' benchmark.getDTeval(the.statement = "dat[,.(mean_age=mean(get(age.name)))]", times = 5, seed = 10)
An Internal function to return the ending index
function.ending.point(all.chars, beginning.index, ...)
function.ending.point(all.chars, beginning.index, ...)
all.chars |
all the characters of the statement |
beginning.index |
specifies the index of the first character |
... |
provision for additional arguments |
The getDTeval() function facilitates the translation of the original coding statement to an optimized form for improved runtime efficiency without compromising on the programmatic coding design. The function can either provide a translation of the coding statement, directly evaluate the translation to return a coding result, or provide both of these outputs
getDTeval( the.statement, return.as = "result", coding.statements.as = "character", eval.type = "optimized", envir = .GlobalEnv, ... )
getDTeval( the.statement, return.as = "result", coding.statements.as = "character", eval.type = "optimized", envir = .GlobalEnv, ... )
the.statement |
refers to the original coding statement which needs to be translated to an optimized form. This value may be entered as either a character value or as an expression. |
return.as |
refers to the mode of output. It could return the results as a coding statement (return.as = "code"), an evaluated coding result (return.as = "result", which is the default value), or a combination of both (return.as = "all"). |
coding.statements.as |
determines whether the coding statements provided as outputs are returned as expression objects (return.as = "expression") or as character values (return.as = "character", which is the default). |
eval.type |
a character value stating whether the coding statement should be evaluated in its current form (eval.type = "as.is") or have its called to get() and eval() translated (eval.type = "optimized", the default setting). |
envir |
Specify the environment for the required function. .GlobalEnv is set as default |
... |
provision for additional arguments |
# Using getDTeval to calculate mean age dat<-formulaic::snack.dat age.name<-'Age' getDTeval(the.statement = 'dat[,.(mean_age=mean(get(age.name)))]',return.as = 'result')
# Using getDTeval to calculate mean age dat<-formulaic::snack.dat age.name<-'Age' getDTeval(the.statement = 'dat[,.(mean_age=mean(get(age.name)))]',return.as = 'result')
Internal Function that translates programmatic designs into optimized coding statements for faster calculations
translate.fn.calls( the.statement, function.name = "get(", envir = .GlobalEnv, ... )
translate.fn.calls( the.statement, function.name = "get(", envir = .GlobalEnv, ... )
the.statement |
original coding statement to perform the required calculation. Must be provided as a character value. |
function.name |
Name of the function to be translated to an optimized form. Parameter values should be either 'get(' or 'eval('. 'get(' is set as default |
envir |
Specify the environment for the required function. .GlobalEnv is set as default |
... |
provision for additional arguments |