extractFunctions: Extract and Remove Nested Functions

extractFunctionsR Documentation

Extract and Remove Nested Functions

Description

This function extracts nested named functions (not anonymous functions) from a function and returns both these nested functions and the modified function with the functions removed.

This deals with nested functions but does not indicate where the extracted functions occured.

The purpose of this is to facilitate refactoring code and moving nested functions to separate functions that can be reused and tested separately from the original function.

mkGlobalsLocal can also be used to update both the extracted functions and the original function to fix calls to include the additional non-local arguments.

Usage

extractFunctions(fun)

Arguments

fun

the function to be processed

Value

A list with 2 elements

newFun

the modified version of the original function

nested

a named list of the nested functions

Author(s)

Duncan Temple Lang

See Also

mkGlobalsLocal


duncantl/CodeAnalysis documentation built on June 12, 2025, 6:44 a.m.