Title: | Trace Function Parameter Types |
---|---|
Description: | The 'R' language includes a set of defined types, but the language itself is "absurdly dynamic" (Turcotte & Vitek (2019) <doi:10.1145/3340670.3342426>), and lacks any way to specify which types are expected by any expression. The 'typetracer' package enables code to be traced to extract detailed information on the properties of parameters passed to 'R' functions. 'typetracer' can trace individual functions or entire packages. |
Authors: | Mark Padgham [aut, cre] , Filip Krikava [ctb] (Author of original 'injectr' code on which this package builds; https://github.com/PRL-PRG/injectr), covr authors [cph] (Original authors of sections of code from 'covr' package included here in modified form.) |
Maintainer: | Mark Padgham <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.2.002 |
Built: | 2024-12-25 05:27:12 UTC |
Source: | https://github.com/mpadge/typetracer |
Traces are by default appended to previous traces. This function can be used to clean those previous ones, to enable subsequent calls to generate new traces that are not appended to previous ones.
clear_traces()
clear_traces()
(Invisibly) A single logical value indicating whether or not traces were successfully cleared.
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () print (x) # Then call 'clear_traces' to remove them: clear_traces () # Trying to load again wil then indicate 'No traces found': x <- load_traces () # Traces should also always be "uninjected": uninject_tracer (f)
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () print (x) # Then call 'clear_traces' to remove them: clear_traces () # Trying to load again wil then indicate 'No traces found': x <- load_traces () # Traces should also always be "uninjected": uninject_tracer (f)
Inject parameter tracer into one function
inject_tracer(f, trace_lists = FALSE)
inject_tracer(f, trace_lists = FALSE)
f |
A function (that is, an object of class "function", and not a character string). |
trace_lists |
If |
Nothing (will error on fail).
The tracer is defined in the internal typetracer_header()
function.
This uses an options
variable defined on package load for the current
tempdir
, defining a single location where all traced values are dumped.
This is done via options
to allow both multi-threaded function calls and
calls via callr to be traced.
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()
Load traces of parameter types
load_traces(files = FALSE, quiet = FALSE)
load_traces(files = FALSE, quiet = FALSE)
files |
If |
quiet |
If |
A 'data.frame' of traces, including names of functions and parameters, and values of each parameter traced in both unevaluated and evaluated forms.
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () print (x) # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () print (x) # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()
Trace all parameters for all functions in a specified package
trace_package( package = NULL, pkg_dir = NULL, functions = NULL, types = c("examples", "tests"), trace_lists = FALSE )
trace_package( package = NULL, pkg_dir = NULL, functions = NULL, types = c("examples", "tests"), trace_lists = FALSE )
package |
Name of package to be traced (as character value). |
pkg_dir |
For "types" including "tests", a local directory to the source code of the package. (This is needed because installed versions do not generally include tests.) |
functions |
Optional character vector of names of functions to trace. Defaults to tracing all functions. |
types |
The types of code to be run to generate traces: one or both
values of "examples" or "tests" (as for |
trace_lists |
If |
A data.frame
of data on every parameter of every function as
specified in code provided in package examples.
## Not run: res <- trace_package ("rematch") res <- trace_package (pkg_dir = "/<path>/<to>/<local>/<pacakge>") ## End(Not run)
## Not run: res <- trace_package ("rematch") res <- trace_package (pkg_dir = "/<path>/<to>/<local>/<pacakge>") ## End(Not run)
This function removes traces previous injected into functions with the inject_tracer function.
uninject_tracer(f)
uninject_tracer(f)
f |
A function (that is, an object of class "function", and not a character string). |
Logical value indicating whether or not tracer was able to be removed ("uninjected").
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()
f <- function (x, y, z, ...) { x * x + y * y } inject_tracer (f) val <- f (1:2, 3:4 + 0., a = "blah") x <- load_traces () # Traces should always be "uninjected": uninject_tracer (f) # Traces may also be removed: clear_traces ()