Refactor R Code with AI Assistance
refactor.Rd
This function refactors R code with the assistance of an AI chatbot.
Arguments
- file
character, file name of a file containing R code to be refactored or a character string containing R code to be refactored
- ...
Additional arguments to pass to the chat_completion() function.
Value
The refactored code either to the console (if the input `file` was a character string) or written to a file (if the input was a file name).
Examples
if (FALSE) {
# Create a sample R function file
cat("my_sum <- function(a, b) {", "return(a + b)", "}",
file = "sample_function.R")
# Refactor the R function and return the output
refactored_function <- refactor(file = "sample_function.R")
# Refactor the R function and write the output to the same file
refactor(file = "sample_function.R")
}