lemur is an R package that provides a wrapper for the OpenAI GPT API. It is a repackaging of code I originally developed for the GPTscreenR package. I created this package for my personal use and it is not planned to ever be released to CRAN.
You can install the development version of lemur from GitHub with:
# install.packages("devtools")
devtools::install_github("wilkox/lemur")
Using lemur requires an OpenAI API key, which you must store in an R
environmental variable called OPENAI_API_KEY
. OpenAI charges fees to
use their API. To obtain and set up an API key:
- Create an OpenAI account, if you don’t have one already.
- Once you have created and signed in to your account, go to the View API Keys page.
- Click on the ‘Create new secret key’ button.
- Give your new key a name, for example ‘lemur’, and click ‘Create secret key’.
- The page will display your new secret API key. You must copy the key now, as it will never be displayed again.
- Store your API key in an R environmental variable by adding the
following line to your
.Renviron
file:OPENAI_API_KEY=<your secret API key goes here>
. There are a few different ways to edit this file:- On any operating system, you can use the function
usethis::edit_r_environ()
from the usethis package to open and edit your.Renviron
file. - On macOS or Linux, you can create or edit a file in your home
directory called
~/.Renviron
. - You can also make an
.Renviron
file for a particular project. I strongly recommend that you do not check this file into a version control system like git, as this means other people with access to the repository (including the public, if the repository is publicly accessible) can see your secret key.
- On any operating system, you can use the function
To check that you have set the environmental variable successfully, open
a new R session and load lemur with library(lemur)
. You should see the
following message:
✔ The `OPENAI_API_KEY` environmental variable is set
If instead you see:
✖ The `OPENAI_API_KEY` environmental variable is not set
this means the environmental variable has not been set correctly. Note that this does not check whether or not you have stored a valid key.