0

I trying to produce this output character string

CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History")(PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0

using the paste function as below

paste("CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History")(PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0")

I am getting an error

Error: unexpected numeric constant in "paste("CONTAINS(ORIG_DOC,'SECTIONS("7"

Not sure what I am missing here, any help is much appreciated.

  • 2
    quotes need to be escaped inside other quotes, so replace the `"` with `\"` in your string – Rorschach Sep 18 '15 at 04:27
  • @bunk not sure I follow, I tried `paste("CONTAINS(ORIG_DOC,'SECTIONS( \ "7 - Past Medical/Surgical History")(PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0")` , now its showing me `Error: unexpected symbol in "paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History")(PRECISE FORM"` – Bridgeport Byron Tucker Sep 18 '15 at 04:43
  • `paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\")(PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0")` outputs `[1] "CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\")(PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"` – xxfelixxx Sep 18 '15 at 04:44
  • i.e. replace all instances of `"` with `\"` – xxfelixxx Sep 18 '15 at 04:45
  • @xxfelixxx , ah, that did it but that changed my output now, I am seeing few \ `"CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\")(PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"`....I dont need those \ – Bridgeport Byron Tucker Sep 18 '15 at 04:55
  • 1
    Yes, it is just a matter of display. Try `out <- paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\")(PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"); cat(out,'\n')`. –  Sep 18 '15 at 04:59
  • @Pascal, oooh I am passing this output from paste function into a query ...`dbGetQuery(connect_JDCB, paste("....`, i wont be able to cat to get rid of the extra \ – Bridgeport Byron Tucker Sep 18 '15 at 05:02
  • And? It didn't work or you didn't try? I didn't tell to use `cat()`. I just show you that what you see doesn't exist. –  Sep 18 '15 at 05:04
  • `noquote(paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\")(PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"))` – xxfelixxx Sep 18 '15 at 05:04
  • @Pascal, i agree with you – Bridgeport Byron Tucker Sep 18 '15 at 05:11
  • @xxfelixxx, that worked perfect, – Bridgeport Byron Tucker Sep 18 '15 at 05:29

1 Answers1

0

Escape all double-quotes " as \" and use noquote:

> txt = noquote(paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\") (PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"))
> txt
[1] CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History") (PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0
>
xxfelixxx
  • 6,512
  • 3
  • 31
  • 38