Backslash in Password in R [duplicate] - r

This question already has answers here:
How to escape backslashes in R string
(3 answers)
Closed 5 years ago.
I’m trying to connect with a database. I use the r-package “RODBC” and the password contains a backslash. Is there a possibility to handle this problem?
library(RODBC)
channel <- odbcConnect("database", uid="theuid", pwd=”whyisherea\backslash”,
believeNRows=FALSE)

You may define your string this way
pwd_string <- "whyisherea\\backslash"

Related

Why it is unable to write \delta inside a print command in "R"? [duplicate]

This question already has answers here:
Error: '\R' is an unrecognized escape in character string starting "C:\R"
(5 answers)
R - Unable to replace unrecognized escape symbol "\&" in character string
(1 answer)
Closed 24 days ago.
I want to insert a delta inside a print command in R. Expect \delta all the greek letters are coming without any error. However, the following error is prompted when trying to print \delta using the sprintf command. Can you help?
I tried searching for an answer and found one. But the solution was to use a forward slash which obviously won't work in my case.

In R, how to change working directory more easily? [duplicate]

This question already has answers here:
Escaping backslash (\) in string or paths in R
(4 answers)
Closed 1 year ago.
In how to change working directory more easily?
Currently, if we use 'setwd',we have to add many '\', sometimes it's boring
Is there any easier way for this ? (Just like Python can add 'r' )
setwd('C:\Users\Administrator\Desktop\myfolder') # can't work
setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
You could use r (for raw string) and add parenthesis:
> r"(C:\Users\Administrator\Desktop\myfolder)"
[1] "C:\\Users\\Administrator\\Desktop\\myfolder"
>
And now:
setwd(r"(C:\Users\Administrator\Desktop\myfolder)")
Or reading from clipboard automatically adds the extra slashes:
setwd(readClipboard())

Adding strings at the back of an existing string help please [duplicate]

This question already has an answer here:
Add a prefix to all rows in R
(1 answer)
Closed 2 years ago.
df<- data.frame(Speaker=c('Abraham','Wassimo','Fredrick','Richard','Ravish','Rubina','Laura'),Age=c(45,47,39,3
3,36,28,30))
#data frame
df
gsub('.*^','Mr/Mrs.',df$Speaker)
results
Mr/Mrs.Abraham
Mr/Mrs.Wassimo
Mr/Mrs.Fredrick
Mr/Mrs.Richard
Mr/Mrs.Ravish
Mr/Mrs.Rubina
Mr/Mrs.Laura
I can not figure out how to add a string after the names though. Can anyone help me add a string after the names?
I don't know why you think you need a regex substitution here, just use paste:
df$Speaker <- paste0("Mr/Mrs.", df$Speaker, "text after here")

How to parse windows directory addresses in R? [duplicate]

This question already has answers here:
Escaping backslash (\) in string or paths in R
(4 answers)
Closed 2 years ago.
In R, while parsing a windows directory address or in general parsing a text string with backstrokes throws the following error:
> 'C:\Users'
Error: '\U' used without hex digits in character string starting "'C:\U"
How to parse such strings?
With R>4.0.0, it is possible to parse such strings with following syntax:
> r"(C:\Users)"
[1] "C:\\Users"
Note that, () are part of syntax. For simplicity, one can also use r"{...}" and r"[...]"

Replace space with %20 in r [duplicate]

This question already has answers here:
How to Convert "space" into "%20" with R
(4 answers)
Closed 6 years ago.
I have following string:
url <- https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green carot
I want to replace the space between green and carot with %20
>url
https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green%20carot
there are some functions to work with url.
In base R use URLencode
url <- "https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green carot"
URLencode(url)
#> [1] "https://www.google.mu/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=green%20carot"
For a straight string replacement use:
> gsub(" ", "%20", url)
Though, a URL encode function like URLencode() would be better.

Resources