Skip to content

Alternative functional interface #675

@vorpalvorpal

Description

@vorpalvorpal

The very wonderful package openxlsx2 has the same sort of object oriented design as ellmer, but it also provides a functional interface that feels much more natural for R.

So in xlsx2 you can use the object oriented approach:

wb_workbook( # create a workbook object 
  )$add_worksheet("Motor Trend Car Road Tests" # add a worksheet
  )$add_data_table(x = mtcars # add some data
  )$open() # open it in excel

Or equivalently:

wb_workbook() |>
  wb_add_worksheet("Motor Trend Car Road Tests") |>
  wb_add_data_table(x = mtcars) |>
  wb_open()

Although the two approaches do the same thing, the second feels much more natural. It also allows much more easy discovery of available functions and accessing of the help files for those functions.

Would you consider creating a similar alternative functional interface for ellmer? It could be a simple wrapper around the object oriented approach.

chat <- function(chat_obj, ...){
  chat_obj$chat(...)
  return(chat_obj)
}
new_chat <- chat_anthropic()
new_chat <- chat(new_chat, "what's 2 + 2")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions