chatAI4R: Chat-Based Interactive Artificial Intelligence for R

CRAN CRAN_latest_release_date CRAN :total status badge chatAI4R status badge



chatAI4R, Chat-based Interactive Artificial Intelligence for R, is an R package designed to integrate the OpenAI API and other APIs for artificial intelligence (AI) applications. This package leverages large language model (LLM)-based AI techniques, enabling efficient knowledge discovery and data analysis. chatAI4R provides basic R functions for using LLM and a set of R functions to support the creation of prompts for using LLM. The LLMs allow us to extend the world of R. Additionally, I strongly believe that the LLM is becoming so generalized that “Are you searching Google?” is likely to evolve into “Are you LLMing?”.

chatAI4R is an experimental project aimed at developing and implementing various LLM applications in R. Furthermore, the package is under continuous development with a focus on extending its capabilities for bioinformatics analysis.

About this project and future developments

The functionality for interlanguage translation using DeepL has been separated as the ‘deepRstudio’ package. Functions related to text-to-image generation were separated as the ‘stableDiffusion4R’ package.

Installation of the chatAI4R package

1. Start R / RStudio console.

2. Run the following commands in the R console:

CRAN-version installation

# CRAN-version installation
# Dev-version installation

# Release v0.2.3
devtools::install_github("kumeS/chatAI4R", ref = "v0.2.3")

Installation from source

#For MacOS X, installation from source
#or system("wget --no-check-certificate")
system("R CMD INSTALL v0.2.3.tar.gz")

3. Set the API key according to each Web API.

For example, to obtain an OpenAI API key, please register as a member on the OpenAI website ( and obtain your API key.

#Set your key for the OpenAI API
Sys.setenv(OPENAI_API_KEY = "Your API key")

Create an .Rprofile file in your home directory and add your API key (using the code above) into it.

# Create a file

# [MacOS X] Open the file and edit it
system(paste("open ~/.Rprofile"))

Note: Please be aware of newline character inconsistencies across different operating systems.


Basic usage

Applied usage of the chatAI4R package

Prompts for chatGPT / GPT-4

File Description Prompt
create_flowcharts A prompt to create a flowchart Prompt
create_roxygen2_v01 A prompt to create a roxygen2 description Prompt
create_roxygen2_v02 A prompt to create a roxygen2 description Prompt
edit_DESCRIPTION A prompt to edit DESCRIPTION Prompt
Img2txt_prompt_v01 A prompt to create a i2i prompt Prompt
Img2txt_prompt_v02 A prompt to create a i2i prompt Prompt

R functions

Flowcharts of the R functions were created by GPT-4 + Skrive plugin.

Basic functions

Function Description Script Flowchart
chat4R Chat4R: Interact with GPT-3.5 (default) using OpenAI API (One-shot) Script Flowchart
chat4R_history Use chat history for OpenAI’s GPT model Script Flowchart
completions4R Generate text using OpenAI completions API (One-shot) Script Flowchart
textEmbedding Text Embedding from OpenAI Embeddings API (model: text-embedding-ada-002) Script Flowchart
slow_print_v2 Slowly Print Text Script  
ngsub Remove Extra Spaces and Newline Characters Script  
removeQuotations Remove All Types of Quotations from Text Script  

Basic Secondary Layer Functions

Function Description Script Flowchart
conversation4R Manage a conversation using a chatting history Script Flowchart
autocreateFunction4R Generate and Improve R Functions (experimental) Script  
revisedText Revision for a scientific text Script  

Functions for R package developments

Function Description Script Flowchart
designPackage Design Package for R Script  
supportIdeaGeneration Support Idea Generation from Selected Text or Clipboard Input Script  
enrichTextContent Enrich Text Content Script  
createSpecifications4R Create Specifications for R Function Script  
createRcode Create R Code from Clipboard Content and Output into the R Console Script  
createRfunction Create R Function from Selected Text or Clipboard Content Script  
convertRscript2Function Convert Selected R Script to R Function Script  
OptimizeRcode Optimize and Complete R Code Script  
addCommentCode Add Comments to R Code Script  
addRoxygenDescription Add Roxygen Description to R Function Script  
proofreadEnglishText Proofread English Text During R Package Development via RStudio API Script  
checkErrorDet Check Error Details Script  
checkErrorDet_JP Check Error Details in Japanese via RStudio API Script  
convertScientificLiterature Convert to Scientific Literature Script  
searchFunction Search the R function based on the provided text Script  

Functions for Text Summary

Function Description Script Flowchart
TextSummary Summarize a long text (experimental) Script  
summaryWebScrapingText Summarize Text via Web Scraping of Google Search Script  
TextSummaryAsBullet Summarize Selected Text into Bullet Points Script  
convertBullet2Sentence Convert Bullet Points to Sentences Script  
chatAI4pdf Summarize PDF Text via LLM Script  
extractKeywords Extract Keywords from Text Script  

Interactions and Flow Control Between LLM-based Bots (LLBs)

Function Description Script Flowchart
discussion_flow_v1 Simulates interactions and flow control between three different roles of LLM-based bots (LLBs) Script  

Functions for RIKEN press release (future developments)

Simple usage

One-Shot Chatting

All runs using the chat4R function are One-Shot Chatting. Conversation history is not carried over to the next conversation.

#API: ""

#API: ""

Few-Shots/Chain-Shots Chatting

Executions using the conversation4R function will keep a history of conversations. The number of previous messages to keep in memory defaults to 2.

#First shot

#Second shot

Text Embedding

Converts input text to a numeric vector. The model text-embedding-ada-002 results in a vector of 1536 floats.

textEmbedding("Hello, world!")


Copyright (c) 2023 Satoshi Kume. Released under the Artistic License 2.0.


Kume S. (2023) chatAI4R: Chat-based Interactive Artificial Intelligence for R.

  title={chatAI4R: Chat-Based Interactive Artificial Intelligence for R},
  author={Kume, Satoshi}, year={2023},
  publisher={GitHub}, note={R Package},