-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
…clipr Fix: Reordering concepts
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Comment Code | ||
#' | ||
#' @param code The code to be commented by ChatGPT. | ||
#' @param code The code to be commented by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(comment_code("for (i in 1:10) {\n print(i ** 2)\n}")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
comment_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Add inline comments to the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Add inline comments to the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Complete Code | ||
#' | ||
#' @param code The code to be completed by ChatGPT. | ||
#' @param code The code to be completed by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(complete_code("# A function to square each element of a vector\nsquare_each <- function(")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
complete_code <- function(code) { | ||
complete_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Complete the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Create Variable Name | ||
#' | ||
#' @param code The code for which to give a variable name to its result. | ||
#' @param code The code for which to give a variable name to its result. If not provided, it will | ||
#' use what's copied on the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(create_variable_name("sapply(1:10, function(i) i ** 2)")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
create_variable_name <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Give a good variable name to the result of the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Give a good variable name to the result of the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Document Code (in roxygen2 format) | ||
#' | ||
#' @param code The code to be documented by ChatGPT. | ||
#' @param code The code to be documented by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(document_code("square_numbers <- function(numbers) numbers ** 2")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
document_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Document, in roxygen2 format, this R function: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Document, in roxygen2 format, this R function: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Explain Code | ||
#' | ||
#' @param code The code to be explained by ChatGPT. | ||
#' @param code The code to be explained by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(explain_code("for (i in 1:10) {\n print(i ** 2)\n}")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
explain_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Explain the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Explain the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Find Issues in Code | ||
#' | ||
#' @param code The code to be analyzed by ChatGPT. | ||
#' @param code The code to be analyzed by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(find_issues_in_code("i <- 0\nwhile (i < 0) {\n i <- i - 1\n}")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
find_issues_in_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Find issues or bugs in the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Find issues or bugs in the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Optimize Code | ||
#' | ||
#' @param code The code to be optimized by ChatGPT. | ||
#' @param code The code to be optimized by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(optimize_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
optimize_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Optimize the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Optimize the following R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#' ChatGPT: Refactor Code | ||
#' | ||
#' @param code The code to be refactored by ChatGPT. | ||
#' @param code The code to be refactored by ChatGPT. If not provided, it will use what's copied on | ||
#' the clipboard. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' cat(refactor_code("i <- 10\nwhile (i > 0) {\n i <- i - 1\n print(i)\n}")) | ||
#' } | ||
#' | ||
#' @importFrom clipr read_clip | ||
#' | ||
#' @return A character value with the response generated by ChatGPT. | ||
#' | ||
#' @export | ||
#' | ||
refactor_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) { | ||
prompt <- paste0('Refactor the following R code, returning valid R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"') | ||
code <- paste(gsub('"', "'", code), collapse = "\n") | ||
prompt <- paste0('Refactor the following R code, returning valid R code: "', code, '"') | ||
parse_response(gpt_get_completions(prompt)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.