在r中移动文件时出错

  • 本文关键字:出错 文件 移动 r file
  • 更新时间 :
  • 英文 :


我正试图使用以下代码将一些文件从一个位置移动到另一个位置:

#exclude files with name .maf
filez <- grep(list.files(path="."), pattern='.maf', invert=TRUE, value=TRUE) 
filez <- data.frame(filez)
#select files with sepcial chr at 14 & 15 position in file name
Tumor <- filez %>% filter(between(as.integer(substr(filez, 14, 15)), 01, 09)) 
dir.create("Tumor")
file.move(Tumor$filez, "Tumor")

然而我得到错误

file.move(Tumor$filez, "Tumor")
Error in argchk_move_files(files = files, destinations = destinations,  : 
Assertion on 'files' failed: Must be of type 'character', not 'factor'.

我不知道为什么会出现错误。

我在一个文件夹中设置了一些文件来说明:

> list.files(".")
[1] "abc01.maf" "abc02.maf" "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"
[7] "abc07.maf"

将一些文件放入向量中(这与您有点不同,因为我认为您得到的所有文件都不是.maf,但这已经足够接近了(:

> filez <- grep(list.files(path="."), pattern='.maf', value=TRUE)
> filez
[1] "abc01.maf" "abc02.maf" "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"
[7] "abc07.maf"

现在,使用从位置4和5的数值得出的条件对该向量进行子集处理,数值在3和6之间:

> filez[dplyr::between(as.integer(substr(filez, 4,5)), 3, 6)]
[1] "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"

完成。无需创建数据帧或使用filter

最新更新