Skip to content

Commit

Permalink
Merge pull request #22 from jcrodriguez1989/fix.jcr.minor_issues_for_…
Browse files Browse the repository at this point in the history
…clipr

Fix: Reordering concepts
  • Loading branch information
jcrodriguez1989 authored Mar 18, 2023
2 parents c366680 + 9241b58 commit da2ff76
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 38 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Imports:
clipr,
httr,
jsonlite,
miniUI,
rstudioapi,
shiny,
utils,
clipr
utils
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(explain_code)
export(find_issues_in_code)
export(optimize_code)
export(refactor_code)
importFrom(clipr,read_clip)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,content)
Expand Down
8 changes: 6 additions & 2 deletions R/comment_code.R
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))
}
8 changes: 6 additions & 2 deletions R/complete_code.R
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))
}
8 changes: 6 additions & 2 deletions R/create_unit_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
#'
#' Create `{testthat}` test cases for the code.
#'
#' @param code The code for which to create unit tests by ChatGPT.
#' @param code The code for which to create unit tests by ChatGPT. If not provided, it will use
#' what's copied on the clipboard.
#'
#' @examples
#' \dontrun{
#' cat(create_unit_tests("squared_numbers <- function(numbers) {\n numbers ^ 2\n}"))
#' }
#'
#' @importFrom clipr read_clip
#'
#' @return A character value with the response generated by ChatGPT.
#'
#' @export
#'
create_unit_tests <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) {
code <- paste(gsub('"', "'", code), collapse = "\n")
prompt <- paste0(
'Create a full testthat file, with test cases for the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"'
'Create a full testthat file, with test cases for the following R code: "', code, '"'
)
parse_response(gpt_get_completions(prompt))
}
8 changes: 6 additions & 2 deletions R/create_variable_name.R
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))
}
8 changes: 6 additions & 2 deletions R/document_code.R
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))
}
8 changes: 6 additions & 2 deletions R/explain_code.R
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))
}
8 changes: 6 additions & 2 deletions R/find_issues_in_code.R
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))
}
8 changes: 6 additions & 2 deletions R/optimize_code.R
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))
}
8 changes: 6 additions & 2 deletions R/refactor_code.R
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))
}
5 changes: 3 additions & 2 deletions man/comment_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/complete_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/create_unit_tests.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/create_variable_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/document_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/explain_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/find_issues_in_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/optimize_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/refactor_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da2ff76

Please sign in to comment.