| callFunction {jrc} | R Documentation |
Trigger a function call
Description
Calls a function in a web page by its name. It can also pass a list of arguments for the function and save the returned result to a variable.
Usage
callFunction(
name,
arguments = NULL,
assignTo = NULL,
wait = 0,
sessionId = NULL,
thisArg = NULL,
...
)
Arguments
name |
Name of the function. If the function is a method of some object
its name must contain the full chain of calls (e.g. |
arguments |
List of arguments for the function. Note that in JavaScript arguments must be given in a fixed order, naming is not necessary and will be ignored. |
assignTo |
Name of a variable to which will be assigned the returned value of the called function. |
wait |
If |
sessionId |
An ID of the session to which the function call should be sent. Can also be a vector of multiple
session IDs. If |
thisArg |
JavaScript functions (methods) can belong to some object, which
is referred to as |
... |
further arguments passed to |
Details
JavaScript counterpart is jrc.callFunction(name, arguments, assignTo, package, internal).
Its arguments are:
name-
Name of an R function. If function name hasn't been previously added to the list of allowed functions (see
allowFunctionsorallowedFunctionsargument ofopenPage), attempt to call it from a web page will require manual authorization on the R side. arguments(optional)-
arguments for the function. This should be an Array (for unnamed arguments) or an Object with argument names as keys (for named arguments).
assignTo(optional)-
Name of the variable to which the returned value of the function will be assigned in the R session. If the variable name hasn't been previously added to the list of allowed variables (see
allowVariablesorallowedVariablesargument ofopenPage), attempt to assign it from a web page will require manual authorization on the R side. package(optional)-
If the function needs to be imported from an installed package, name of this package.
internal(optional)-
Whether assignment of the function returned value should happen internally or not. If
true, result will be stored in the session environment and can be accessed from the outside withgetSessionVariablefunction. Iffalse, result will be saved to the outer environment of the app (seesetEnvironment). By default, usestruefor variables that already exist in the session environment (seesetSessionVariablesorsessionVariablesargument of theopenPagefunction) andfalseotherwise.
This function is a wrapper
around callFunction method of class Session.
See Also
authorize, allowFunctions, allowVariables,
setEnvironment, getSessionIds.
Examples
## Not run:
# to run this example an installed web browser is required
openPage()
callFunction("alert", list("Some alertText"))
callFunction("Math.random", assignTo = "randomNumber")
sendCommand("alert(randomNumber)")
closePage()
## End(Not run)