Import multiline SQL query to single string

后端 未结 7 1007
傲寒
傲寒 2020-12-24 03:11

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 
         


        
7条回答
  •  我在风中等你
    2020-12-24 03:53

    The versatile paste() command can do that with argument 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"
    

提交回复
热议问题