tanyrseay
tanyrseay

Reputation: 31

Read a CSV Directly Into R as a String

I have a CSV file that I want to read into R without making it a Data Frame. It seems like it would be quite simple but I can't figure out how to do it. I quite literally just want the CSV file to read in as it would appear in a text editor. The reason for this is I need to feed the string into an API.

Using read.csv() obviously won't work for this because it automatically reads in as a df.

Upvotes: 1

Views: 94

Answers (1)

Mark
Mark

Reputation: 4537

Try readLines()

This will read in the file with each line being a value in a vector. You'll need to then wrap that in a paste(readLines(),collapse="\n") to have it be a single text string that could be passed to an API.

Upvotes: 4

Related Questions