Search code examples
rpaste

R paste string with collapse - How to keep string with quotes?


I have a problem with the quotes in pasting two strings together.

I want an output like this: query= "sql query","port"

I tried:

      query<-c("sql query","port")
      paste(queryString,collapse=",")

which gives:"sql query,port"

Also tried this:

        query<-c("sql query")
        query<-paste(query,"port",sep=",")

which also gives: "sql query,port"

Without the quotes in the right place the query won't run. How can I keep them ?


Solution

  • Try this:

    queryq <- toString(shQuote(query))
    

    which gives:

    cat(queryq, "\n")
    ## "sql query", "port"