Open sckott opened 4 years ago
this is complicated. the way R parses functions, it doesn't maintain the same number of lines, e.g.,
remotes::install_github("ropenscilabs/astr")
library(astr)
foo <- function(x = NULL) {
if (!is.null(x)) x * 10
return(x)
}
w = ast_decompose(foo)
fun = ast_recompose(w)
cat(fun)
#> function (x = NULL)
#> {
#> if (!is.null(x))
#> x * 10
#> return(x)
#> }
In this example, the if statement is all on one line, which isn't that uncommon. So the recomposed function adds an additional line, with the if statement over 2 lines.
If we wanted to re-insert mutated functions into the original file structure they were pulled from, we'd need to account for these additional lines and push any further lines down.
coming back to later
Right now
write_mutated_pkg
makes completely new R files, and writes the mutated fxns into those files. Maybe copy over R files from original location, and use line number/column position to replace lines - so that roxygen tags/constants/etc are retained as those things could affect outcomes