Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.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中添加反斜杠的粘贴函数_R_Paste_Names - Fatal编程技术网

在r中添加反斜杠的粘贴函数

在r中添加反斜杠的粘贴函数,r,paste,names,R,Paste,Names,这可能是一个非常特殊的请求,但我想在R中的每个文件之前的file.path字符串末尾粘贴一个反斜杠(\)。出于某种原因,R不喜欢函数:sep=“\”,我不知道为什么。。。任何帮助都将不胜感激 # Image files files <- c("image1.bmp", "image2.bmp", "image3.bmp", "image4.bmp", "image5.bmp") # Pasting file paths and file names file.paths <-

这可能是一个非常特殊的请求,但我想在R中的每个文件之前的file.path字符串末尾粘贴一个反斜杠(\)。出于某种原因,R不喜欢函数:sep=“\”,我不知道为什么。。。任何帮助都将不胜感激

# Image files 
files <- c("image1.bmp", "image2.bmp", "image3.bmp", "image4.bmp", "image5.bmp")

# Pasting file paths and file names 
file.paths <- paste("C:/Users/John/Desktop/images/", files, sep="\")

# Desired output 
C:/Users/John/Desktop/images\image1.bmp
C:/Users/John/Desktop/images\image2.bmp
C:/Users/John/Desktop/images\image3.bmp
C:/Users/John/Desktop/images\image4.bmp
C:/Users/John/Desktop/images\image5.bmp
#图像文件

文件
\
可以工作,但在控制台输出中它显示为双反斜杠,但是您不能使用
消息
cat
来查看它的自然外观


file.path尝试\\。可能会显示为双反斜杠,但实际上,如果您
cat
它也是双反斜杠,那么在指定
sep
paste0
时,您需要使用
paste()
,而不是
paste0()
没有
sep
参数。您可能是指粘贴(“C:/Users/John/Desktop/images/”,files,sep=“\\”
?是的,粘贴是@arg0naut91已经提到的正确功能,
粘贴(“C:/Users/John/Desktop/images”,files,sep=“\\”
对您有用吗?