mutant icon indicating copy to clipboard operation
mutant copied to clipboard

write_mutated_pkg: replacing lines instead of writing new lines?

Open sckott opened this issue 5 years ago • 2 comments

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

sckott avatar May 18 '20 18:05 sckott

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.

sckott avatar May 21 '20 19:05 sckott

coming back to later

sckott avatar May 21 '20 19:05 sckott