Skip to content

Commit

Permalink
Merge pull request #21 from denisabd/clipr_revised
Browse files Browse the repository at this point in the history
Clipboard copied code with clipr
  • Loading branch information
jcrodriguez1989 authored Mar 18, 2023
2 parents 4c129ce + 4d2e05c commit c366680
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Imports:
miniUI,
rstudioapi,
shiny,
utils
utils,
clipr
4 changes: 2 additions & 2 deletions R/comment_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
comment_code <- function(code) {
prompt <- paste0('Add inline comments to the following R code: "', code, '"')
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"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/create_unit_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#'
#' @export
#'
create_unit_tests <- function(code) {
create_unit_tests <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) {
prompt <- paste0(
'Create a full testthat file, with test cases for the following R code: "', code, '"'
'Create a full testthat file, with test cases for the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"'
)
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/create_variable_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
create_variable_name <- function(code) {
prompt <- paste0('Give a good variable name to the result of the following R code: "', code, '"')
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"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/document_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
document_code <- function(code) {
prompt <- paste0('Document, in roxygen2 format, this R function: "', code, '"')
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"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/explain_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
explain_code <- function(code) {
prompt <- paste0('Explain the following R code: "', code, '"')
explain_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) {
prompt <- paste0('Explain the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/find_issues_in_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
find_issues_in_code <- function(code) {
prompt <- paste0('Find issues or bugs in the following R code: "', code, '"')
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"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/optimize_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
optimize_code <- function(code) {
prompt <- paste0('Optimize the following R code: "', code, '"')
optimize_code <- function(code = clipr::read_clip(allow_non_interactive = TRUE)) {
prompt <- paste0('Optimize the following R code: "', paste(gsub('"', "'", code), collapse = "\n"), '"')
parse_response(gpt_get_completions(prompt))
}
4 changes: 2 additions & 2 deletions R/refactor_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @export
#'
refactor_code <- function(code) {
prompt <- paste0('Refactor the following R code, returning valid R code: "', code, '"')
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"), '"')
parse_response(gpt_get_completions(prompt))
}

0 comments on commit c366680

Please sign in to comment.