Skip to contents

Converts a data frame to a string format, intended for sending it to a LLM (or for display or logging).

Usage

df_to_string(df, how = c("wide", "long"))

Arguments

df

A data.frame object to be converted to a string

how

In what way the df should be converted to a string; either "wide" or "long". "wide" presents column names on the first row, followed by the row values on each new row. "long" presents the values of each row together with the column names, repeating for every row after two lines of whitespace

Value

A single string representing the df

See also

Examples

cars |>
  head(5) |>
  df_to_string() |>
  cat()
#> speed, dist
#> 4, 2
#> 4, 10
#> 7, 4
#> 7, 22
#> 8, 16