Replace double slashes with single backslash

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Replace double slashes with single backslash

Anbu A
Hi All,
I am able to replace "r" with "x" for the word "Users" just for a test run.
*Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
works fine
But when I try to replace "\\" with "\".
*newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
prompt ">" to complete the code. Not working. There is something on
backslashes to be "masked".
Any help would be appreciated.

                       fpath                         new_col
1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\

Thanks,
Anbu.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Replace double slashes with single backslash

Bert Gunter-2
"\" is an escape in R. See ?Quotes for details.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Dec 28, 2020 at 12:56 PM Anbu A <[hidden email]> wrote:

> Hi All,
> I am able to replace "r" with "x" for the word "Users" just for a test run.
> *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
> works fine
> But when I try to replace "\\" with "\".
> *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
> prompt ">" to complete the code. Not working. There is something on
> backslashes to be "masked".
> Any help would be appreciated.
>
>                        fpath                         new_col
> 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>
> Thanks,
> Anbu.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Replace double slashes with single backslash

jholtman
Why do you want to replace '\\' with '\' in the file names?  They are
actually single '\' in the character string, but are printing out as '\\'.
see example below:

    > x <- 'a\\b'
    > x
    [1] "a\\b"
    > nchar(x)
    [1] 3

Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Dec 28, 2020 at 1:20 PM Bert Gunter <[hidden email]> wrote:

> "\" is an escape in R. See ?Quotes for details.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Mon, Dec 28, 2020 at 12:56 PM Anbu A <[hidden email]> wrote:
>
> > Hi All,
> > I am able to replace "r" with "x" for the word "Users" just for a test
> run.
> > *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
> > works fine
> > But when I try to replace "\\" with "\".
> > *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
> > prompt ">" to complete the code. Not working. There is something on
> > backslashes to be "masked".
> > Any help would be appreciated.
> >
> >                        fpath                         new_col
> > 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> >
> > Thanks,
> > Anbu.
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Replace double slashes with single backslash

Anbu A
Thank you, Jim. That clarifies. I am trying to pass this path in a loop and
read the files  associated with the path.
Yes the length is 26 where double quotes are counted as single quotes. Let
me try to read the files using the collected path.

Really appreciate it.

Thanks,
Anbu

On Mon, Dec 28, 2020 at 6:27 PM jim holtman <[hidden email]> wrote:

> Why do you want to replace '\\' with '\' in the file names?  They are
> actually single '\' in the character string, but are printing out as '\\'.
> see example below:
>
>     > x <- 'a\\b'
>     > x
>     [1] "a\\b"
>     > nchar(x)
>     [1] 3
>
> Jim Holtman
> *Data Munger Guru*
>
>
> *What is the problem that you are trying to solve?Tell me what you want to
> do, not how you want to do it.*
>
>
> On Mon, Dec 28, 2020 at 1:20 PM Bert Gunter <[hidden email]>
> wrote:
>
>> "\" is an escape in R. See ?Quotes for details.
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Mon, Dec 28, 2020 at 12:56 PM Anbu A <[hidden email]> wrote:
>>
>> > Hi All,
>> > I am able to replace "r" with "x" for the word "Users" just for a test
>> run.
>> > *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
>> > works fine
>> > But when I try to replace "\\" with "\".
>> > *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
>> > prompt ">" to complete the code. Not working. There is something on
>> > backslashes to be "masked".
>> > Any help would be appreciated.
>> >
>> >                        fpath                         new_col
>> > 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> >
>> > Thanks,
>> > Anbu.
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > [hidden email] 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.
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.