Is there a way to use read.csv to read from a string value rather than a file in R?

Viewed 30163

I'm writing an R package where the R code talks to a Java application. The Java application outputs a CSV formatted string and I want the R code to be able to directly read the string and convert it into a data.frame.

6 Answers

Using a tidyverse approach, you can just specify a text value

library(readr)
read_csv(file = "col1, col2\nfoo, 1\nbar, 2")
# A tibble: 2 x 2
 col1   col2
 <chr>  <dbl>
1 foo       1
2 bar       2
Related