Package 'kwb.context'

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] , Michael Rustler [ctb] , FAKIN [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph]
Maintainer: Hauke Sonnenberg <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-10-25 05:02:27 UTC
Source: https://github.com/KWB-R/kwb.context

Help Index


Example function calling abline

Description

Example function calling abline

Usage

example_crossline(...)

Arguments

...

arguments passed to abline


Example function calling example_crossline twice

Description

Example function calling example_crossline twice

Usage

example_one_plot(..., h = 5, v = 5)

Arguments

...

arguments passed to plot

h

position of horizontal line

v

position of vertical line


Example function calling example_one_plot three times

Description

Example function calling example_one_plot three times

Usage

example_three_plots()

Get the context tree (currently from a global variable "CONTEXTn")

Description

Get the context tree (currently from a global variable "CONTEXTn")

Usage

getContext(number = getDefault("getContext", "number"))

Arguments

number

Context number (see initContext)

Value

a list of function calls


Get a function call from the context tree

Description

Get a function call from the context tree

Usage

getFunctionCall(i, number = getDefault("getFunctionCall", "number"))

Arguments

i

Index of the function call as it is stored in the context

number

Number of the context (see initContext)


Initialise the variable storing the full function call context

Description

Initialise the variable storing the full function call context

Usage

initContext(number = getDefault("initContext", "number"))

Arguments

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

Description

Print the context of a function call

Usage

printContext(number = getDefault("printContext", "number"), indent = "  ")

Arguments

number

Number of the context to print (see initContext)

indent

string used to indent nested function calls in the output


Recall a function call that is stored in the context tree

Description

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.

Usage

recall(funCall = getFunctionCall(i), i = toIndex(id), id = "", ...)

Arguments

funCall

Function call to be re-called. By default it is taken from the context tree at index i

i

Index of the function call in the context tree

id

As an alternative to specifying the index i of the call in the call tree you can specify it by its ID (as shown by when calling printContext.

...

argument = value pairs overriding the argument setting of the stored function call.

Examples

## 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)