zekrom-vale / ZekDex

ZekDex: A comprehensive R package and CSV files for Pokémon data. Features National Dex Info, Legendary/Mythical Groupings, Base Stats, Evolution Info, and Random Pokémon Generation. Data sourced from Bulbapedia, covering generations I-IX. Ideal for data scientists, Pokémon enthusiasts, and researchers.
Other
1 stars 0 forks source link

R: reduce redundency #16

Open zekrom-vale opened 5 months ago

zekrom-vale commented 5 months ago

There is some redundancy in the code. It should use utility and helper functions to streamline and standardize the process.

Find the range where e falls

for (range in ranges) { if (e >= exp$medium_slow(range[1]) && e <= exp$medium_slow(range[2])) {

Use uniroot to find the root of the function medium_slow(n) - e

    root <- uniroot(function(n) exp$medium_slow(n) - e, range)
    return(floor(root$root))
}

}

Return NA if no solution was found

return(NA)


- [x] `requireNamespace` functions
- [x] `EXTRACT_REGEX = "([^()]+)(?:\\(([^()]+)\\))?"`
- [x] Mutate across characters if `""` replace with `NA_character_`
```r
mutate(across(
    where(is.character),
    ~ if_else(.=="", NA_character_, ., NA_character_)
))