0

I have been stuck on this for quite a while. I am trying to build a sql query to write to file, but I keep writing the text 'c("...")' as part of the output file, as if the concatenate function in R was being interpreted very literally.

I have eliminated the write() function itself, toString(), and the paste0() used as part of building the final output string. The first occurrence of the 'c' appears in the output of sQuote. When I try doing a call to sQuote() in interactive mode, I don't get the same behaviour:

Browse[2]> sQuote(sqlTableColumnValues)
[1] "‘c(\"0\", \"XXX0\", \"XXX056\", \"XXX139\", \"XXX143\", \"XXX144\", \"XXX159\", \"XXX171\", \"XXX185\", \"XXX188\", \"XXX192\", \"XXX202\", \"XXX239\", \"XXX240\", \"XXX245\", \"XXX256\", \"XXX271\", \"XXX303\", \"XXX319\", \"XXX326\", \"XXX334\", \"XXX357\", \"XXX363\", \"XXX368\", \"XXX390\", \"XXX391\", \"XXX417\", \"XXX426\", \"XXX431\", \"XXX439\", \"XXX447\", \"XXX456\", \"XXX461\", \"XXX466\", \"XXX475\", \"XXX483\", \"XXX488\", \"XXX491\", \"XXX521\", \"XXX531\", \n\"XXX538\", \"XXX541\", \"XXX548\", \"XXX550\", \"XXX581\")’"
Browse[2]> str(sQuote(sqlTableColumnValues))
 chr "‘c(\"0\", \"XXX0\", \"XXX056\", \"XXX139\", \"XXX143\", \"XXX144\", \"XXX159\", \"XXX171\", \"XXX185\","| __truncated__
Browse[2]> tst <- c("foo","bar") #my own interactive test
Browse[2]> tst
[1] "foo" "bar"
Browse[2]> sQuote(tst) #does not show the 'c' character in the result
[1] "‘foo’" "‘bar’"
Browse[2]> 

What is causing this discrepancy and how can I stop the 'c(...)' being written to my output file?

Update: dput output as requested:

Browse[2]> dput(sqlTableColumnValues)
structure(list(`1` = c("0", "XXX0", "XXX056", "XXX139", 
"XXX143", "XXX144", "XXX159", "XXX171", "XXX185", ... #etc, I've truncated.

I don't yet understand what that means / what to do with this info. :-/

rstruck
  • 1,174
  • 4
  • 17
  • 27
  • 1
    My guess is that `sqlTableColumnValues` is a list that holds a character vector rather than being a character vector itself. You should provide the result of `dput(sqlTableColumnValues)` to make your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Jan 28 '15 at 20:55
  • oh... is it because I created sqlTableColumnValues with a 'head()' statement? The dataset had over 2 million rows so I just grabbed the first 45 with head(fulldf,45)... I guess that doesn't create a vector :-( – rstruck Jan 28 '15 at 21:06
  • @MrFlick - I understand this now; thanks for the pointer. I was passing a vector but there is an interim call to break up the vector into chunks (in anticipation of the large dataset. This returning a **list** of chunks. The answer was therefore to use the [[ ]] operator to send the next chunk (e.g. chunk[[i]] ) as the argument representing sqlTableColumnValues. THANK YOU for the hint!! – rstruck Jan 28 '15 at 21:37

0 Answers0