check.whitelist: Check whether a call only calls functions or uses variables...

Description Usage Arguments Details Examples

View source: R/whitelist.r

Description

The function extracts in a nested fashion all names of called functions and used variables in a call object. It can look up in whitelists whether these symbols are allowed or in blacklists whether these symbols are forbidden. Whitelists and blacklists are simple character vectors with the function / variable names.

Usage

1
2
check.whitelist(call, wl.funs = NULL, wl.vars = NULL, wl.calls = NULL,
  bl.funs = NULL, bl.vars = NULL)

Arguments

call

the call object

wl.funs

a character vector of the function names that are allowed (whitelisted). If NULL ignored.

wl.vars

a character vector of the variable names that are allowed (whitelisted). If NULL ignored.

wl.calls

a named list of quoted calls that are allowed. The list names should be the call names, i.e. call[[1]]. For example, one may not generally whitelist the function 'library' (who knows what can happen if a library has functions with the same name than some whitelisted function but different behavior) Yet one may allow the explicit call 'library(dplyr)'. In this case, we could set wl.calls = alist(library=library(dplyr)).

bl.funs

a character vector of the function names that are forbidden (blacklisted). If NULL ignored.

bl.vars

a character vector of the variable names that are forbidden (blacklisted). If NULL ignored.

Details

Returns a list (ok, fb.funs, fb.vars, msg) where ok is FALSE if a forbidden symbol has been found and otherwise TRUE. fb.funs and fb.vars list the forbidden function calls or variable names that have been found. msg is a default error message that can be shown if the call did not pass the check.

Examples

 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
## Not run: 


  dir = path.package("WhitelistEval")
  wl.funs = parse.whitelist.yaml(file.path(dir,"lists/StratTournWhiteList.yaml"))
  call = quote({
    eval(1+1)
    base::print
    y <<- 5
   # print("Hi")
    print("Ok")
    filter(group_by(x,y), a==5)
    ggplot()
  })



  check.whitelist(call, wl.funs = wl.funs)
  check.whitelist(call, bl.funs="print", wl.calls=alist(print=print("Ok")))

  li = as.expression(list(call, call))
  check.whitelist(li, wl.funs = wl.funs)
  check.whitelist(li, bl.funs="print", wl.calls=alist(print=print("Ok")))

## End(Not run)

skranz/whitelistcalls documentation built on May 30, 2019, 3:04 a.m.