本文介绍了功能串联路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在连接路径的功能?

Is there an existing function to concatenate paths?

我知道实现起来并不难,但是...除了注意尾随/(或\)之外,我还需要注意适当的OS路径格式检测(即我们是否编写C:\dir\file/dir/file).

I know it is not that difficult to implement, but still... besides taking care of trailing / (or \) I would need to take care of proper OS path format detection (i.e. whether we write C:\dir\file or /dir/file).

正如我所说,我相信我知道如何执行它;问题是:我应该这样做吗?该功能是否已存在于现有的R包中?

As I said, I believe I know how to implement it; the question is: should I do it? Does the functionality already exist in existing R package?

推荐答案

是,file.path()

R> file.path("usr", "local", "lib")
[1] "usr/local/lib"
R>

对于包中的文件也有同样有用的system.path():

There is also the equally useful system.path() for files in a package:

R> system.file("extdata", "date_time_zonespec.csv", package="RcppBDT")
[1] "/usr/local/lib/R/site-library/RcppBDT/extdata/date_time_zonespec.csv"
R>

将获得文件extdata/date_time_zonespec.csv,而与

  1. 安装软件包的位置,以及
  2. 操作系统

这非常方便.最后,还有

which is very handy. Lastly, there is also

R> .Platform$file.sep
[1] "/"
R>

如果您坚持手动进行.

这篇关于功能串联路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:47