连接路径的函数? [英] Function to concatenate paths?

查看:12
本文介绍了连接路径的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有连接路径的现有函数?

Is there an existing function to concatenate paths?

我知道实现起来并不难,但仍然......除了处理尾随 /(或 )之外,我还需要注意适当的操作系统路径格式检测(即我们是写C:dirfile 还是/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:dirfile 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> 

如果你坚持手动操作.

这篇关于连接路径的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆