From ligges at statistik.tu-dortmund.de  Wed Feb 29 19:24:09 2012
From: ligges at statistik.tu-dortmund.de (Uwe Ligges)
Date: Wed, 29 Feb 2012 19:24:09 +0100
Subject: [Rd] Replace back slashes with forward slashes?
In-Reply-To: <4F4E6C24.5000901@prodsyse.com>
References: <4F4E626F.6050805@prodsyse.com>
	<CB641CDA-51A7-4F42-BB36-E074911F2372@r-project.org>
	<4F4E6C24.5000901@prodsyse.com>
Message-ID: <4F4E6D49.2040106@statistik.tu-dortmund.de>



On 29.02.2012 19:19, Spencer Graves wrote:
> Hi, Simon:
>
> On 2/29/2012 10:04 AM, Simon Urbanek wrote:
>> On Feb 29, 2012, at 12:37 PM, Spencer Graves wrote:
>>
>>> Hello, All:
>>>
>>>
>>> What can people tell me about converting back slashes to forward
>>> slashes in character strings?
>>>
>>>
>> That's it's trivially done with
>>
>> gsub("\\", "/", x, fixed=TRUE)
>>
>> Where x is the character string (and I suppose you are aware of it
>> since you are using it below).
>
> It does not work for me. Consider the following:
>
>
>  > x <- 'c:\Users\'
> Error: '\U' used without hex digits in character string starting "c:\U"


This is something your editor could do much better than R.

Uwe



>
> This is one reason I needed to use "scan". Even if I could get past
> this, consider the following:
>
>
>  > x <- '\t'
>  > gsub('\\', '/', x, fixed=TRUE)
> [1] "\t"
>
>
> It seems far from trivial, which is why I wrote this function and am
> looking for a better one.
>
>
> Thanks for the reply.
>
>
> Spencer
>>
>> The rest of this e-mail makes absolutely no sense to me -- what
>> exactly are you taking about? What else do you want to achieve?
>>
>> Cheers,
>> Simon
>>
>>
>>
>>
>>
>>
>>> Several years ago, Prof. Ripley provided a solution, which I lost and
>>> have not been able to find.
>>>
>>>
>>> Below please find a function to do this. I do not find this very
>>> satisfactory, however, because it uses "scan" and therefore operates
>>> on an input not a character string. Unless someone suggests something
>>> better, I plan to add this to the "sos" package and issue a new
>>> release very soon. (The new release is needed, because the
>>> RSiteSearch capability has been modified in a way that breaks the
>>> current "findFn" core of "sos".)
>>>
>>>
>>> Thanks,
>>> Spencer
>>>
>>> back2forwardslash<- function (nmax = 1, pattern = "\\", replacement =
>>> "/") {
>>> x<- scan(what = character(), quote = pattern, nmax = nmax)
>>> x.<- gsub(pattern, replacement, x, fixed = TRUE)
>>> paste(x., collapse = " ")
>>> }
>>>
>>> (x<- back2forwardslash())
>>> c:\Users\
>>>
>>> # nmax must be one more than the number of embedded blanks
>>> (x3<- back2forwardslash(3))
>>> c:\u\a b\c d
>>>
>>>
>>> --
>>> Spencer Graves, PE, PhD
>>> President and Chief Technology Officer
>>> Structure Inspection and Monitoring, Inc.
>>> 751 Emerson Ct.
>>> San Jos?, CA 95126
>>> ph: 408-655-4567
>>> web: www.structuremonitoring.com
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>



[Rd] Replace back slashes with forward slashes?
Uwe Ligges