= "XXXXXXXXXXXXX9FRPvvB85H_7YA0VqK_mlyiU94" my_gemini_api_key
ai in r
an experiment
We’re still figuring out how ai, and LLM’s in particular, will affect data science. You might be asked in an interview to show how you might use it in some novel way. Here’s something you can talk about.
all of this motivated by this video
1. get a gemini api key
2. create an r-script.
Enter the line below and paste in your api key
3. paste your key below and execute
4. install ellmer
ellmer: an R - LLM package
install.packages("ellmer")
then
5. install usethis
this makes it easy to change settings
install.packages("usethis")
library(usethis)
then
6. set your google-gemini api key
do this, which opens a file for you to edit in the Editor:
::edit_r_environ() usethis
Now you should look to the Editor and add this line
# in the .renviron file do
=blah-blah-blah-whatever GEMINI_API_KEY
then
7. restart R (click session)
then
8. load ellmer
library(ellmer)
9. then: choose a provider
Use gemini unless you know what you’re doing. It’s free. Learn more here.
= chat(name="google_gemini") chat
10. use it like this
$chat("what does the r-function apropos do?")
chat
# I forgto what command I wanted, but I know it had "app" in it
apropos("app")
11. you can use it like you do in the browser
$chat("extract the name and age of each sentence I give you")
chat
$chat("david, 17, felt like it was day 21")
chat
$chat("jaime is turning seventeen this coming September.") chat
12. it can extract numbers from strings and help with code
$chat("separate this into month,day and year: july12_1938 and show me how to this using tidyverse")
chat
# another example
$chat("how do extract the numbers from th list") chat
13. programming tools
<- type_object(
type_person color = type_string(),
age = type_number()
)
<- list("red is 42 now", "green is 17",
prompts "blue, 25, climbs inside", "yellow will soon hit the big 5-0")
$chat_structured(prompts[[1]], type = type_person) chat
14. one last query
$chat("what is an interesting statistic about the palmerpenguins data")
chat
# can you make a plot to display it?