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