Description Usage Arguments Details Value Examples
Detect if there is some global variable in a function.
1 | detectGlobal(realResult, tolerance = 0, theoResult = "", result = TRUE)
|
tolerance |
Some keyword are detected as global variable whereas they are not. Tolerance is the number of false detection that should be ignored. |
realResult |
Either the name of a function (see example 1), or a function with its argument (see example 2). |
theoResult |
The theoritical result of the computation of the function with its argument. |
result |
TRUE or FALSE: shall realResult should be the same than the theoResult, or not ? This is usefull to test conter example. |
Detect if there is some global variable in a function.
None
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ### example 1
f <- function(x)x^2
detectGlobal(f)
g <- function(x)x^2*y
detectGlobal(g)
###########
### example 2
f <- function(x)x^2
### the next line should ring a bell, because 2^2 is not 8
detectGlobal(f(2),8)
### the next line should not ring a bell, because 2^2 is not 8, and we ask for conter-example
detectGlobal(f(2),8,FALSE)
###########
### example 3
h <- function(x){
apply(matrix(1:x),1,length)
}
### 'length' is detected as a global variable whereas it is a function
detectGlobal(h)
### So we use tolerance=1
detectGlobal(h,,,1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.