Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 更换'\';由'/';在中不使用scan()或剪贴板_R - Fatal编程技术网

R 更换'\';由'/';在中不使用scan()或剪贴板

R 更换'\';由'/';在中不使用scan()或剪贴板,r,R,我想用“/”替换“\”,不管它在输入字符串中出现多少次 我读过: 但它们都给出了通过剪贴板粘贴或扫描()读取目录路径的解决方案 我想把目录路径作为一个变量 示例代码: directory_path = 'D:\demo\app' gsub( '\', '/', directory_path ) 但这是一个错误 > directory_path = 'D:\demo\app' Error: '\d' is an unrecognized escape in character stri

我想用“/”替换“\”,不管它在输入字符串中出现多少次

我读过:

但它们都给出了通过剪贴板粘贴或扫描()读取目录路径的解决方案

我想把目录路径作为一个变量

示例代码:

directory_path = 'D:\demo\app'

gsub( '\', '/', directory_path )
但这是一个错误

> directory_path = 'D:\demo\app'
Error: '\d' is an unrecognized escape in character string starting "'D:\d"
像这样逃离他们:

test <- c("D:\\demo\\app")

像这样逃避:
testI我想知道有多少关于R需要双重逃避
“\”
的问题。我怀疑他们有数百人。嗯,也许不是。这是搜索的结果,但大多数答案都不准确:路径将由用户输入,不能要求用户用双斜杠输入。如何处理这一部分?我提出这个问题就是为了这个。在其他问题中找不到此表单的答案。目录路径将由不知道转义字符的用户输入。他将给出“D:\demo\app”,否则不能要求他给出。如何应对?
gsub("\\\\", "/", test)