在 r 中移动文件时出现错误

发布于 2025-01-09 07:08:14 字数 651 浏览 0 评论 0原文

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

#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'.

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

I am trying to move some files from one location to another using below code:

#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")

However I getting error

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'.

I donot know why error is coming.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2025-01-16 07:08:14

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

> 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"

完成。无需创建数据框或使用过滤器

I've set up some files in a folder to illustrate:

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

Get some files into a vector (this is a bit different to you because I think you are getting all files that aren't .maf but this is close enough):

> 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"

Now subset that vector using the condition derived from the numeric value in positions 4 and 5 being between 3 and 6:

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

Done. No need to create a data frame or use filter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文