Sys.glob expansion

ε祈祈猫儿з 提交于 2021-01-27 06:13:12

问题


I am trying to use Sys.glob to open a file called "apcp_sfc_latlon_subset_19940101_20071231.nc". The following command works:

> Sys.glob(file.path("data/train", "apcp*"))
[1] "data/train/apcp_sfc_latlon_subset_19940101_20071231.nc"

But this command doesn't return anything. I'm don't know why it doesn't work.

> Sys.glob(file.path("data/train", "apcp", "*"))
character(0)

I want the "apcp" bit as it's own argument because I will be passing a variable instead of a hard coded string.

Thank you.


回答1:


file.path("data/train", "apcp", "*") returns "data/train/apcp/*" whereas file.path("data/train", "apcp*") returns "data/train/apcp*".

Thus in the first case you are looking for files in the subdirectoy apcp, and in the (working) case you are looking for files which begin apcp within the data\train directory.

If you want to be able to pass the apcp component as a argument, using paste0 will work

starting <- "apcp"

file.path("data/train", paste0(starting, '*', collapse =''))

# "data/train/apcp*"


来源:https://stackoverflow.com/questions/17938916/sys-glob-expansion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!