假设存在路径C:/coverage/Homo_sapiens.sort.add_exon1_coverage.txt,欲提取Homo_sapiens.sort.add_exon1_coverage.txt文件名,则用到basename函数和start、stop参数,命令行如下所示:
filename<-'C:/coverage/Homo_sapiens.sort.add_exon1_coverage.txt' substr(basename(filename), start = 1, stop = 4) #表示提取文件名的第一个字符至第四个字符,即Homo substr(basename(filename), start = 23, stop = 27)#表示提取文件名的第23个字符至第27个字符,即exon1 paste(substr(basename(path), start = 1, stop = 4),substr(basename(path), start = 23, stop = 27)) #将两个字符黏贴起来
效果如下图所示: