Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_mutated_pkg: replacing lines instead of writing new lines? #9

Open
sckott opened this issue May 18, 2020 · 2 comments
Open

write_mutated_pkg: replacing lines instead of writing new lines? #9

sckott opened this issue May 18, 2020 · 2 comments

Comments

@sckott
Copy link
Owner

sckott commented May 18, 2020

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
Copy link
Owner Author

sckott commented May 21, 2020

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
Copy link
Owner Author

sckott commented May 21, 2020

coming back to later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant