为什么使用粘贴创建的文件名中有空格? [英] why there is a gap in the file name created using paste?
问题描述
我试图使用R编写文件,并且为了区分每个文件,我试图每次在函数中添加一个不同的后缀.
I was trying to write a file using R and in order to distinguish each file, i tried to add a different suffix each time in a function.
例如……
counts <- function(counts_file)
{
..............................
..............................
name <- substr(counts_file,1,5)
file <- paste(name,".cpm.csv")
write.csv(countpermillion, file)
}
但是当我运行功能counts("JKNC1.bam.tsv")
时,创建的输出文件就是这样的
JKNE3 .cpm.csv
,即JKNEE3 and .cpm.csv
之间存在间隙.我在这里做错什么了?
But when i run the function counts("JKNC1.bam.tsv")
, the output file created is like this
JKNE3 .cpm.csv
i.e there is a gap between the JKNEE3 and .cpm.csv
. What am i doing wrong here?
谢谢 Upendra
Thanks Upendra
推荐答案
默认分隔符为空格. paste(name,".cpm.csv",sep="")
应该在这里做您想要的.或者,您可以使用
The default separator is a space. paste(name,".cpm.csv",sep="")
should do what you want here. Alternately, you could use
paste0(name,".cpm.csv")
有关此文档,可以在控制台上键入?paste
来找到.
The documentation for this can be found by typing ?paste
at the console.
这篇关于为什么使用粘贴创建的文件名中有空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!