在 r 中移动文件时出现错误
I am getting error, while moving files in r
我正在尝试使用以下代码将一些文件从一个位置移动到另一个位置:
#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
.
我正在尝试使用以下代码将一些文件从一个位置移动到另一个位置:
#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
.