https://github.com/flowr-analysis/mutatr
Code Mutation for R
https://github.com/flowr-analysis/mutatr
Last synced: 9 months ago
JSON representation
Code Mutation for R
- Host: GitHub
- URL: https://github.com/flowr-analysis/mutatr
- Owner: flowr-analysis
- Created: 2024-11-28T07:30:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-31T04:23:16.000Z (12 months ago)
- Last Synced: 2025-03-18T01:42:08.570Z (9 months ago)
- Language: R
- Size: 140 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MutatR
Mutate R code.
## Available Mutators
We currently support the following mutations (in no particular order):
- Arithmetic operator replacement:
| Original | Mutation 1 | Mutation 2 | Mutation 3 |
|----------|------------|------------|------------|
| `+` | `-` | `*` | `/` |
| `-` | `+` | `*` | `/` |
| `*` | `+` | `-` | `/` |
| `/` | `+` | `-` | `*` |
- Branch condition replacement:
- Conditions of `if` statements and `while` loops are replaced by `TRUE` or `FALSE`
- Condition boundary mutation:
| Original | Mutation |
|----------|----------|
| `>` | `>=` |
| `>=` | `>` |
| `<` | `<=` |
| `<=` | `<` |
- Function name replacement:
| Original | Mutation 1 | Mutation 2 |
|-------------|-------------|-------------|
| `lapply` | `sapply` | `vapply` |
| `sapply` | `lapply` | |
| `vapply` | `sapply` | |
| `isTRUE` | `isFALSE` | |
| `isFALSE` | `isTRUE` | |
| `[[` | `[` | |
| `any` | `all` | |
| `all` | `any` | |
| `==` | `identical` | |
| `identical` | `==` | |
| `union` | `intersect` | `setdiff` |
| `intersect` | `union` | `setdiff` |
| `setdiff` | `union` | `intersect` |
- Literal mutation:
- Numeric literals are replaced by `NA` or in- or decremented by 1
- Logical literals are replaced by their negation
- Character literals are modified by appending to the end, removing the first character, or by replacing it with an empty string
- This is only done when the string does not appear inside typical logging functions, like `print`, `cat`, `message`, or `log_trace`
- Logic operator replacement:
| Original | Mutation |
|----------|----------|
| `&` | `\|` |
| `\|` | `&` |
| `&&` | `\|\|` |
| `\|\|` | `&&` |
- Relational operator replacement:
| Original | Mutation |
|----------|----------|
| `==` | `!=` |
| `!=` | `==` |
| `>` | `<=` |
| `>=` | `<` |
| `<` | `>=` |
| `<=` | `>` |
- Sign replacement:
| Original | Mutation |
|----------|----------|
| `+` | `-` |
| `-` | `+` |
- Function replacement
- Calls whose result is not assigned by `<-`, `<<-`, `->`, `->>`, or `=` are removed
- Calls to `length` are replaced by `0`, `1`, and `5`
- "is"-checkes (`is.character`, `is.logical`, ... , and relation operators) are replaced by `TRUE` and `FALSE`
- Return value replacement:
| Original | Mutation |
|-----------------|----------|
| `NULL` | `42` |
| everything else | `NULL` |
- Vector modification:
- Wenn the function `c` is called, we either remove and element, add an additional, or remove all elements
- Call insertion
- A call to `stop` or `warning` is inserted into blocks (`{ ... }`)