Jes*_*ton 5 string r special-characters
我试图将\R 中的特殊转义字符存储为字符串的一部分。
x = "abcd\efg"
# Error: '\e' is an unrecognized escape in character string starting ""abcd\e"
x = "abcd\\efg"
# Works
Run Code Online (Sandbox Code Playgroud)
问题是,这x实际上是我作为 API Web 调用的一部分传递的密码,因此我需要找到一种方法让字符串存储单斜杠文字,才能使其正常工作。
使用忽略文字命令的示例:
> x = r"(abcd\efg)"
> y = "https://url?password="
> paste(x, y, sep = "")
[1] "abcd\\efg123"
> # What I need is for it to return
[1] "abcd\efg123"
> z = paste(y, x, sep = "")
> z
[1] "https://url?password=abcd\\efg"
> cat(z)
https://url?password=abcd\efg
Run Code Online (Sandbox Code Playgroud)
当我z作为 API 命令的一部分传递时,我收到“错误凭据”消息,因为它是\\作为字符串的一部分发送的。cat将其正确返回到控制台,但它似乎没有像打印回去那样发送它。