MyNixOS website logo
Description

AI Assistant to Write and Understand R Code.

An R console utility that lets you ask R related questions to the 'OpenAI' large language model. It can answer 'how-to()' questions by providing code, and 'whatis()' questions by explaining what given code does. You must provision your own key for the 'OpenAI' API <https://platform.openai.com/docs/api-reference>.

Air - AI help for R coding

Air is an R package that lets you ask R related questions to OpenAI and get working code, or explanations of code.

Features

HowTo

You can ask "how-to" questions to get working code solutions:

howto("get a vector of the second element from a list of vectors")
# sapply(list_of_vectors, function(v) v[2])

howto("extract the second largest number from a vector")
# vec <- c(1, 5, 3, 9, 7)
# sort(unique(vec), decreasing = TRUE)[2]

WhatIs

You can ask "what-is" questions to get detailed explanations of code you cannot understand:

whatis("paste0(vector1, vector2)")
# [Abbreviated output]
# Overall, the R function `paste0` concatenates vectors after 
# converting them to characters. It combines corresponding 
# elements of `vector1` and `vector2` without any separator.
#
# Sub-expressions:
# - `paste0`: The function used for concatenation without any separator.
#
# Example:
#
# ```R
# vector1 <- c("Apple", "Banana", "Cherry")
# vector2 <- c("Pie", "Bread", "Jam")
#
# result <- paste0(vector1, vector2)
# print(result)
# ```
#
# Output:
# ```
# [1] "ApplePie"   "BananaBread"   "CherryJam"
# ```

AI Large Language Model (LLM) from OpenAI

Air requires your OpenAI API key (see Setup direcitons below), which it stores securely in your operating system's keyring.

Future features under consideration:

  • Keep conversation session so we can ask followup questions.
  • General AI role (e.g., tellme()).
  • Create custom roles

Feel free to leave issues or reach out to maintainers with any questions.

Installation

Air is currently only available from Github. Use your favorite installer tool as follows:

Using pak:

# install.packages("pak") - if you haven't already
pak::pkg_install("github::soumyaray/air")

or, Using devtools:

# install.packages("devtools") - if you haven't already
devtools::install_github("soumyaray/air")

Setup

Air needs your API key for OpenAI.

Creating an OpenAI Key

Create an OpenAI acount if you don't have one at: https://platform.openai.com/signup

Ensure you have API credits by:

  1. Make sure your billing information with OpenAI is up-to-date:
    https://platform.openai.com/account/billing/overview
  2. Create an OpenAI API key:
    https://platform.openai.com/api-keys
  3. Note which of one of OpenAI's models you wish to use:
    https://platform.openai.com/docs/models

Please set your API credentials (key and model) either in your your R environment, or in your system's secure keyring (suggested).

Setting your OpenAI credentials in your R environment:

Your R environment can specify user level environment variables stored in a local .Renviron file. Please note that anyone with access to this file can steal your credentials – make sure not to expose it to any other processes.

Please read about .Renviron files if you are unfamiliar with them. Briefly, to set your OpenAI API credentials, we suggest using usethis::edit_r_environ() to open the correct .Renviron file for editing. You may create VAR=value pairs to set your API key and preferred model in this file - for example:

OPENAI_KEY="sk-my-api-key"
OPENAI_MODEL="gpt-4-1106-preview"

You will have to restart the R session for these new environment variables to be loaded. You can confirm they are present in your R environment by using:

Sys.getenv("OPENAI_KEY")
Sys.getenv("OPENAI_MODEL")

Securely setting OpenAI credentials in your system keyring

Alternatively, we recommend storing your key and model preference securely in your operating system's keyring using Air's built-in functions for accessing the keyring.

We recommend you use your system's keyring to enter it safely in a system popup window. But you may choose to set it programatically at the console, but note that it will be stored in your .Rhistory file where it could get compromised:

# Safely set the key in a system popup
air::set_key()

# or programatically set it:
air::set_key("api-key-goes-here")

You must also specify the OpenAI model you prefer to use:

# Set your preferred model
set_model("gpt-4-1106-preview")

# or use the default model (see documentation)
set_model()

Note that your system may occasionally popup windows to get your login password to access the keyring for these credentials. We suggest using an 'always accept' option in such popups to reduce how often you see them.

You may later delete your key and model from your keyring using:

# Wipes away all keyring credentials stored by this package
delete_keyring_credentials()

Usage

library(air)

howto("zip vectors foo and bar together, creating a list of vectors which are pairs of elements from the original two vectors")
# zip_list <- mapply(c, foo, bar, SIMPLIFY=FALSE)

Testing

Please run tests using devtools::test()

Contributing

Please first submit Github issues for bugs or feature suggestions, for discussion on whether and how to fix or implement them. We greatly welcome pull requests on open issues that are slated for development. We also welcome suggestions or fixes for documentation.

Metadata

Version

0.2.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows