Package 'injectr'

Title: Inject code to existing functions
Description: Allow one to inject arbitrary code at the entry point or at the exit point of an existing function.
Authors: Filip Krikava [aut, cre] (ORCID: <https://orcid.org/0000-0002-0478-6202>)
Maintainer: Filip Krikava <[email protected]>
License: MIT + file LICENSE
Version: 0.1
Built: 2026-07-15 01:00:31 UTC
Source: https://github.com/PRL-PRG/injectr

Help Index


Duplicate an R object

Description

Creates a duplicate of an R object using R's native duplication mechanism.

Usage

create_duplicate(x)

Arguments

x

An R object to duplicate. Must not be NULL.

Value

A duplicate of x.


Injects code into an existing function.

Description

The code argument is recorded without evaluation and it will be inserted at the beginning of the fun. If it is a symbol, its value will be looked starting in the callee frame. If where is not onentry it will be wrapped in on.exit call. If where is onerror, the wrapped code will further make the code to run only in the case the function failed with an error condition.

Usage

inject_code(code, fun, where = "onentry", wrap = FALSE)

Arguments

code

the code that should be inserted.

fun

the function into which the code should be inserted.

where

indicates at which point of the fun invocation the given code shall run. It can be one of the following: onentry, onexit, onsuccess, onerror.

wrap

indicates if it the given code should be wrapped in an anonymous function (TRUE) or inserted as is (FALSE).

Details

This function modifies the original function.

Value

NULL invisibly


Get the memory address of an R object

Description

Returns the address of an object's underlying S-expression. This low-level helper is primarily useful when testing whether two objects share storage.

Usage

sexp_address(x)

Arguments

x

An R object. Must not be NULL.

Value

A character scalar containing the hexadecimal memory address of x.