[R] Delete Comment Lines from SQL String as a Vector

David Winsemius dwinsemius at comcast.net
Tue Feb 22 00:21:15 CET 2011


On Feb 21, 2011, at 6:14 PM, Phil Spector wrote:

> Mai -
>
>> sql=c("-- This is a comment line",
> +          "select sysdate  -- This is a comment Text" ,
> +          " from dual ")
>> use = sub('--.*$','',sql)
>> use[use != '']
> [1] "select sysdate  " " from dual "
>
> Although to get it to print the way you listed, you need
> to reduce the width of the line:
>
>> options(width=20)
>> use[use != '']
> [1] "select sysdate  "
> [2] " from dual "
>

I would imagine the next question to be answered along these lines:

 > paste(sub("--.+", "", sql), collapse="")
[1] "select sysdate   from dual "

> 					
> On Tue, 22 Feb 2011, Mai Dang wrote:
>
>> Hi,
>> I tried to remove the text starts by "--" to the end of the line as  
>> below
>>
>>
>> sql=c("-- This is a comment line",
>>        "select sysdate  -- This is a comment Text" ,
>>        " from dual ")
>>> sql
>> [1] "-- This is a comment line"
>> [2] "select sysdate  -- This is a comment Text"
>> [3] " from dual "
>>
>>
>> I try to have this
>>> sql
>> [1] "select sysdate "
>> [2] " from dual "
>>
>> Thank You for your help,
>> Mai Dang

>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list