简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM