为什么以及如何区分文件名的两个构造?
我正在尝试动态创建我需要阅读到R的文件的名称。 我会得到意外的结果,因为我下面构造文件名的两种方法正在产生不同的结果,即使包含文件名的字符向量似乎是相同的,但是R对其进行了不同的对待。
您能帮我理解为什么这是吗?我应该如何在R中(动态)创建文件名?
phe_num <- 1
cross_num <- 1
chr_num <- 1
pfn <- paste0("pred_ukb_pheno",
phe_num,
"_fold",
cross_num,
"_chr",
chr_num,
"_best.dblsmm.txt.profile")
profile_fn <- file.path("/net/mulan/home/fredboe/research/ukb-intervals/dat", "simulations-ding", "DBSLMM", pfn)
file.exists(profile_fn)
#> [1] FALSE
profile_fn
#> [1] "/net/mulan/home/fredboe/research/ukb-intervals/dat/simulations-ding/DBSLMM/pred_ukb_pheno1_fold1_chr1_best.dblsmm.txt.profile"
my_file <- "/net/mulan/home/fredboe/research/ukb-intervals/dat/simulations-ding/DBSLMM/pred_ukb_pheno1_fold1_chr1_best.dbslmm.txt.profile"
file.exists(my_file)
#> [1] TRUE
my_file == profile_fn
#> [1] FALSE
由
创建'm在Ubuntu上使用R 4.2.0操作系统上使用R 4.2.0。
I'm trying to dynamically create names for files that I need to read into R.
I'm getting unexpected results because my two ways of constructing the file name, below, are yielding different results, even though the character vectors containing the file names seem to be the same, yet R treats them differently.
Can you help me to understand why this is? How should I be creating (dynamically) file names in R?
phe_num <- 1
cross_num <- 1
chr_num <- 1
pfn <- paste0("pred_ukb_pheno",
phe_num,
"_fold",
cross_num,
"_chr",
chr_num,
"_best.dblsmm.txt.profile")
profile_fn <- file.path("/net/mulan/home/fredboe/research/ukb-intervals/dat", "simulations-ding", "DBSLMM", pfn)
file.exists(profile_fn)
#> [1] FALSE
profile_fn
#> [1] "/net/mulan/home/fredboe/research/ukb-intervals/dat/simulations-ding/DBSLMM/pred_ukb_pheno1_fold1_chr1_best.dblsmm.txt.profile"
my_file <- "/net/mulan/home/fredboe/research/ukb-intervals/dat/simulations-ding/DBSLMM/pred_ukb_pheno1_fold1_chr1_best.dbslmm.txt.profile"
file.exists(my_file)
#> [1] TRUE
my_file == profile_fn
#> [1] FALSE
Created on 2022-06-20 by the reprex package (v2.0.1)
I'm using R 4.2.0 on Ubuntu 22.04 operating system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的提示是
使您所有人都知道为什么一个人工作,而另一个人则不知道。 它们毕竟有所不同!。
一点点的大亮点会揭示
出一个简单的错字,例如
ls!= sl
。我们都去过那里。计算机是确定性的,并且“做我说的话”,而不是“做我的意思”。
Your cue was that
which gives you everything to know why one works and the other does not. They differ after all!.
A little bit of eyeballing reveals
so you have a simple typo as
ls != sl
.We've all been there. Computers are deterministic and 'do what I say' instead of 'do what I mean'.