| Title: | Get the Function Call Context and Work with it |
|---|---|
| Description: | This package contains functions to get the full tree of function calls that is evaluated when calling a function. The idea is to reuse some of these calls with modified arguments, e.g. to replot a specific plot that was created by an inner plot function that was called from an outer function. |
| Authors: | Hauke Sonnenberg [aut, cre] (ORCID: <https://orcid.org/0000-0001-9134-2871>), Michael Rustler [ctb] (ORCID: <https://orcid.org/0000-0003-0647-7726>), FAKIN [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
| Maintainer: | Hauke Sonnenberg <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-08 06:41:08 UTC |
| Source: | https://github.com/KWB-R/kwb.context |
Example function calling abline
example_crossline(...)example_crossline(...)
... |
arguments passed to |
Example function calling example_crossline twice
example_one_plot(..., h = 5, v = 5)example_one_plot(..., h = 5, v = 5)
... |
arguments passed to |
h |
position of horizontal line |
v |
position of vertical line |
Example function calling example_one_plot three times
example_three_plots()example_three_plots()
n")Get the context tree (currently from a global variable "CONTEXTn")
getContext(number = getDefault("getContext", "number"))getContext(number = getDefault("getContext", "number"))
number |
Context number (see |
a list of function calls
Get a function call from the context tree
getFunctionCall(i, number = getDefault("getFunctionCall", "number"))getFunctionCall(i, number = getDefault("getFunctionCall", "number"))
i |
Index of the function call as it is stored in the context |
number |
Number of the context (see |
Initialise the variable storing the full function call context
initContext(number = getDefault("initContext", "number"))initContext(number = getDefault("initContext", "number"))
number |
Number of the context. You may use different contexts that are numbered. The default context number is 1. |
Print the context of a function call
printContext(number = getDefault("printContext", "number"), indent = " ")printContext(number = getDefault("printContext", "number"), indent = " ")
number |
Number of the context to print (see |
indent |
string used to indent nested function calls in the output |
Recall a function of which the call is stored in the context tree. You may
specify argument settings that override the argument settings of the original
call by passing key = value pairs to this function.
recall(funCall = getFunctionCall(i), i = toIndex(id), id = "", ...)recall(funCall = getFunctionCall(i), i = toIndex(id), id = "", ...)
funCall |
Function call to be re-called. By default it is taken from the
context tree at index |
i |
Index of the function call in the context tree |
id |
As an alternative to specifying the index |
... |
argument = value pairs overriding the argument setting of the stored function call. |
## Not run: # Load the required libraries library(kwb.context) library(kwb.default) # for setDefault() # Set the default context number to 2 (required until now!) funNames <- c(paste0(c("init", "print", "get"), "Context"), "getFunctionCall") for (funName in funNames) { setDefault(funName, number = 2) } # Initialise the context tree (currently it's a global list called "CONTEXT1") initContext() # Call a function that contains a call of logcall() or that calls other # functions that contain calls of logcall(). The logcall()-calls have the # effect that they save the calling context in the global context tree oldpar <- par(mfrow = c(1, 3), no.readonly = TRUE) example_three_plots() # Print the context tree that has been recorded printContext() # Change the order of the original plots recall(i = 8) recall(i = 5) recall(i = 2) # Reset the graphical parameters par(oldpar) # Replot the second plot, now on its own page, but with a different colour, # plot symbol and size recall(i = 5, col = "red", pch = 16, cex = 2) ## End(Not run)## Not run: # Load the required libraries library(kwb.context) library(kwb.default) # for setDefault() # Set the default context number to 2 (required until now!) funNames <- c(paste0(c("init", "print", "get"), "Context"), "getFunctionCall") for (funName in funNames) { setDefault(funName, number = 2) } # Initialise the context tree (currently it's a global list called "CONTEXT1") initContext() # Call a function that contains a call of logcall() or that calls other # functions that contain calls of logcall(). The logcall()-calls have the # effect that they save the calling context in the global context tree oldpar <- par(mfrow = c(1, 3), no.readonly = TRUE) example_three_plots() # Print the context tree that has been recorded printContext() # Change the order of the original plots recall(i = 8) recall(i = 5) recall(i = 2) # Reset the graphical parameters par(oldpar) # Replot the second plot, now on its own page, but with a different colour, # plot symbol and size recall(i = 5, col = "red", pch = 16, cex = 2) ## End(Not run)