In R, how can I import the contents of a multiline text file (containing SQL) to a single string?
The sql.txt file looks like this:
SELECT TOP 100
The versatile paste() command can do that with argument collapse="":
paste()
collapse=""
lines <- readLines("/tmp/sql.txt") lines [1] "SELECT TOP 100 " " setpoint, " " tph " "FROM rates" sqlcmd <- paste(lines, collapse="") sqlcmd [1] "SELECT TOP 100 setpoint, tph FROM rates"