addCommentCode: Add Comments to R Code

View source: R/addCommentCode.R

addCommentCodeR Documentation

Add Comments to R Code

Description

This function adds comments to R code without modifying the input R code. It can either take the selected code from RStudio or read from the clipboard.

Usage

addCommentCode(
  Model = "gpt-4o-mini",
  language = "English",
  SelectedCode = TRUE,
  provider = "auto"
)

Arguments

Model

A character string specifying the model to be used. Default is "gpt-4o-mini" for OpenAI or "gemini-2.0-flash" for Gemini.

language

A character string specifying the language for the comments. Default is "English".

SelectedCode

A logical value indicating whether to use the selected code in RStudio. Default is TRUE.

provider

A character string specifying the API provider. Options: "auto" (default), "openai", "gemini". When "auto", automatically detects available API keys with priority: OpenAI → Gemini.

Details

Add Comments to R Code

Value

A message indicating completion if 'SelectedCode' is TRUE, otherwise the commented code is copied to the clipboard.

Author(s)

Satoshi Kume

Examples

## Not run: 
# Option 1: Auto-detect available API (OpenAI or Gemini)
# Select some text in RStudio and then run the rstudio addins
addCommentCode(Model = "gpt-4o-mini", language = "English", SelectedCode = TRUE)

# Option 2: Explicitly use OpenAI
addCommentCode(Model = "gpt-4o-mini", provider = "openai", SelectedCode = TRUE)

# Option 3: Use Gemini API
addCommentCode(Model = "gemini-2.0-flash", provider = "gemini", SelectedCode = TRUE)

# Option 4: Copy text to clipboard and execute
addCommentCode(Model = "gpt-4o-mini", language = "English", SelectedCode = FALSE)

## End(Not run)

chatAI4R documentation built on Jan. 10, 2026, 5:07 p.m.