[R] Creating/Reading a complex string in R

Christofer Bogaso bogaso.christofer at gmail.com
Tue Jul 18 19:05:17 CEST 2017


Thanks for your pointer.

Is there any way in R how to replace " ' " with " /' " programmatically?

My actual string is quite lengthy, so changing it manually may not be
possible. I am aware of gsub() function, however not sure I can apply
it directly on my original string.

Regards,

On Tue, Jul 18, 2017 at 10:27 PM, John McKown
<john.archie.mckown at gmail.com> wrote:
> Try:
>
> String = '<html>
>   <head>
>     <script type="text/javascript"     <script type="text/javascript">
>       mystatement(\'current\', {\'pac\':[\'\']});
>       mystatement;'
>
>
> To embed a single ' mark in a string delimited by ' marks, you must "escape"
> them by prefixing them with a back-slash \.
>
>
>
> R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
> Copyright (C) 2017 The R Foundation for Statistical Computing
> Platform: x86_64-redhat-linux-gnu (64-bit)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
>   Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
>>
>> String = '<html>
> +   <head>
> +     <script type="text/javascript"     <script type="text/javascript">
> +       mystatement(\'current\', {\'pac\':[\'\']});
> +       mystatement;'
>> String
> [1] "<html>\n  <head>\n    <script type=\"text/javascript\"     <script
> type=\"text/javascript\">\n      mystatement('current', {'pac':['']});\n
> mystatement;"
>
>
>
> On Tue, Jul 18, 2017 at 11:48 AM, Christofer Bogaso
> <bogaso.christofer at gmail.com> wrote:
>>
>> Hi again,
>>
>> Let say I have below string (arbitrary)
>>
>> <html>
>>   <head>
>>     <script type="text/javascript"     <script type="text/javascript">
>>       mystatement('current', {'pac':['']});
>>       mystatement;
>>
>>
>> I want to pass above string to some R variable for further analysis.
>> So I have tried below :
>>
>> String = '<html>
>>   <head>
>>     <script type="text/javascript"     <script type="text/javascript">
>>       mystatement('current', {'pac':['']});
>>       mystatement;'
>>
>> It is not clearly working as I am getting below error :
>>
>> > String = '<html>
>>
>> +   <head>
>>
>> +     <script type="text/javascript"     <script type="text/javascript">
>>
>> +       mystatement('current', {'pac':['']});
>>
>> Error: unexpected symbol in:
>>
>> "    <script type="text/javascript"     <script type="text/javascript">
>>
>>       mystatement('current"
>>
>> >       mystatement;'
>>
>> Error: object 'mystatement' not found
>>
>> >
>>
>>
>> Any pointer how to create my string 'String' based on above would be
>> highly appreciated.
>>
>> Thanks for your time.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> --
> Veni, Vidi, VISA: I came, I saw, I did a little shopping.
>
> Maranatha! <><
> John McKown



More information about the R-help mailing list