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-10-29 04:46:32 UTC |
Source: | https://github.com/repboxr/sourcemodify |
Key internal function fo sourcemodify Returns parsed code as a tibble with detailed information where each subexpression is found in the code
getAugmentedParseData( code, calls = parse(text = code, keep.source = TRUE), line.starts = find.line.starts(code) )
getAugmentedParseData( code, calls = parse(text = code, keep.source = TRUE), line.starts = find.line.starts(code) )
Only works with named arguments.
somo_calls_info( somo, fun, arg_names, arg_pos = NULL, arg_def = NULL, call_pd_rows = NULL, arg_prefix = "" )
somo_calls_info( somo, fun, arg_names, arg_pos = NULL, arg_def = NULL, call_pd_rows = NULL, arg_prefix = "" )
If the function call directly
somo_change_calls_fun_name(somo, fun, new, ignore_if_pkg = TRUE)
somo_change_calls_fun_name(somo, fun, new, ignore_if_pkg = TRUE)
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(). |
The modified somo object
Find the text of the function argument in all calls to fun
somo_find_fun_arg( somo, fun, arg_name = NULL, arg_pos = NULL, arg_def = NULL, call_pd_rows = NULL )
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
somo_find_fun_call(somo, fun)
somo_find_fun_call(somo, fun)
Returns the results from the last somo_find_* call as a tibble
somo_found(somo)
somo_found(somo)
Init a new source modifier object
somo_init(code, start.size = 200)
somo_init(code, start.size = 200)
code |
The R source code as text file |
Returns the modified code of a somo object
somo_make_code(somo)
somo_make_code(somo)
Will by typically used to wrap a function call into another function call that can analyse or modify the result.
somo_surround_calls(somo, funs, pre, post)
somo_surround_calls(somo, funs, pre, post)
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. |
The modified somo object
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.
somo_surround_calls_arg( somo, fun, arg_name = NULL, arg_pos = NULL, pre, post, arg_def = NULL )
somo_surround_calls_arg( somo, fun, arg_name = NULL, arg_pos = NULL, pre, post, arg_def = NULL )
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. |
The modified somo object