Package 'sourcemodify'

Title: Helper functions to modify source code of R scripts
Description: Helper functions to modify source code of R scripts
Authors: Sebastian Kranz
Maintainer: Sebastian Kranz <[email protected]>
License: GPL >= 2.0
Version: 0.1.0
Built: 2024-08-30 05:22:09 UTC
Source: https://github.com/repboxr/sourcemodify

Help Index


Key internal function fo sourcemodify Returns parsed code as a tibble with detailed information where each subexpression is found in the code

Description

Key internal function fo sourcemodify Returns parsed code as a tibble with detailed information where each subexpression is found in the code

Usage

getAugmentedParseData(
  code,
  calls = parse(text = code, keep.source = TRUE),
  line.starts = find.line.starts(code)
)

A simplified interface to somo_find_fun_arg

Description

Only works with named arguments.

Usage

somo_calls_info(
  somo,
  fun,
  arg_names,
  arg_pos = NULL,
  arg_def = NULL,
  call_pd_rows = NULL,
  arg_prefix = ""
)

Change the name of a called function without adapting any arguments

Description

If the function call directly

Usage

somo_change_calls_fun_name(somo, fun, new, ignore_if_pkg = TRUE)

Arguments

somo

The somo object generated with somo_init.

fun

Function name that shall be changed in calls

new

New function name to be called

ignore_if_pkg

If TRUE don't change calls of the form pkg::fun(). If FALSE a call like pkg::fun() will be replaced by just new().

Value

The modified somo object


Find the text of the function argument in all calls to fun

Description

Find the text of the function argument in all calls to fun

Usage

somo_find_fun_arg(
  somo,
  fun,
  arg_name = NULL,
  arg_pos = NULL,
  arg_def = NULL,
  call_pd_rows = NULL
)

Find the text of the function argument in all calls to fun

Description

Find the text of the function argument in all calls to fun

Usage

somo_find_fun_call(somo, fun)

Returns the results from the last somo_find_* call as a tibble

Description

Returns the results from the last somo_find_* call as a tibble

Usage

somo_found(somo)

Init a new source modifier object

Description

Init a new source modifier object

Usage

somo_init(code, start.size = 200)

Arguments

code

The R source code as text file


Returns the modified code of a somo object

Description

Returns the modified code of a somo object

Usage

somo_make_code(somo)

Surround calls to the specified functions

Description

Will by typically used to wrap a function call into another function call that can analyse or modify the result.

Usage

somo_surround_calls(somo, funs, pre, post)

Arguments

somo

The somo object generated with somo_init.

funs

One or several function names.

pre

Text to be added before the function call.

post

Text to be added the function call.

Value

The modified somo object


Surround an argument of specific function

Description

Will by typically used to wrap the argument (like a filenam) of function call into another function call that can analyse or modify the argument.

Usage

somo_surround_calls_arg(
  somo,
  fun,
  arg_name = NULL,
  arg_pos = NULL,
  pre,
  post,
  arg_def = NULL
)

Arguments

somo

The somo object generated with somo_init.

fun

Name of the function whose argument shall be wrapped

arg_name

The name of the argument (must be given if arg_pos is NULL)

arg_pos

Position of the argument (must be given if arg_name is NULL)

pre

Text to be added before the function call.

post

Text to be added the function call.

arg_def

Names of all function arguments in the correct order. The result of calling names(as.list(args(fun))). This argument is optional, but without it matching may fail.

Value

The modified somo object