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.
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*"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With