Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Tue, 29 Jun 2010 21:54:23 +0200

On 29.06.2010 19:19, Bert Gunter wrote:
> Uwe:
>
> Did you forget to add the "fixed = TRUE" parameter to your gsub call in your
> reply?

Yes, thanks.

Uwe

>> gsub("N\\A", "NA", "N\\A")
> [1] "N\\A"
>
>> gsub("N\\A","NA","N\\A",fixed=TRUE)
> [1] "NA"
>
> I only mention it because there is already sufficient confusion that the
> typo may totally bewilder people.
>
> -- Bert
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
>> -----Original Message-----
>> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
>> On Behalf Of Uwe Ligges
>> Sent: Tuesday, June 29, 2010 4:11 AM
>> To: Jason Rupert
>> Cc: r-help_at_r-project.org
>> Subject: Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2
>>
>>
>>
>> On 29.06.2010 12:47, Jason Rupert wrote:
>>> Previously in R 2.9.2 I used the following to convert from an improperly
>> formatted NA string into one that is a bit more consistent.
>>>
>>>
>>> gsub("N\A", "NA", "N\A", fixed=TRUE)
>>>
>>> This worked in R 2.9.2, but now in R 2.11.1 it doesn't seem to work an
>> throws the following error.
>>> Error: '\A' is an unrecognized escape in character string starting "N\A"
>>>
>>> I guess my questions are the following:
>>> (1) Is this expected behavior?
>>> (2) If it is expected behavior, what is the proper way to replace "N\A"
>> with "NA" and "N\\A" with "NA"?
>>
>>
>> If your original text "thestring" contains "N\A", then the R
>> representation is "N\\A", and hence
>>
>> gsub("N\\A", "NA", thestring)
>>
>> If you want to try explicitly, you need to write
>>
>> gsub("N\\A", "NA", "N\\A")
>>
>> If you original text contains two backslashes, both have to be escaped as
>> in
>>
>> gsub("N\\\\A", "NA", thestring)
>>
>> Uwe Ligges
>>
>>
>>> Thank you again for all the help and insight.
>>>
>>> ______________________________________________
>>> R-help_at_r-project.org mailing list
>>> 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.
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> 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.
>



R-help_at_r-project.org mailing list
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. Received on Tue 29 Jun 2010 - 19:56:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jun 2010 - 20:41:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive