Closed lochbika closed 2 years ago
Hey Kai,
Hmmm, that's definitely an unusual case. Not sure why someone would have arbitrarily long space listed in their time units. That's not explicitly covered by the CF Conventions spec.
Admittedly the canonical implementation of units parsing, udunits2
, does parse your case:
> library(udunits2)
udunits system database read
> ud.is.parseable('days since 850-1-1 00:00:00')
[1] TRUE
> ud.is.parseable('days since 850-1-1 00:00:00')
[1] TRUE
And it since strsplit
takes a regular expression, it's easy to split on one or more spaces with a one character change:
> strsplit('days since 850-1-1 00:00:00', ' +')
[[1]]
[1] "days" "since" "850-1-1" "00:00:00"
I'll push a patch, but it's unlikely that it will get incorporated into a release in the near future. Thanks for the report, though.
Hi James, thanks for the quick reply. The solution with regex is great!
Hmmm, that's definitely an unusual case. Not sure why someone would have arbitrarily long space listed in their time units. That's not explicitly covered by the CF Conventions spec.
I also wouldn't expect it. But it happened while I was reading some CMIP5 output into R. It was just a double space which is apparently enough, however.
Thanks for the fix.
Hi,
version: 0.3-6
I just found out that the parsing of the time unit string in the
nc.get.time.series
function fails if the string contains multiple spaces. For instance:is parsed perfectly fine. However
throws an error:
The source of the error is the two white spaces between "since" and "850-1-1". I guess
strsplit
returns empty elements in the split vectortime.split
.A possible workaround could be to first run
time.split <- strsplit(f$dim$time$units, " ")[[1]]
and then drop empty elements with something liketime.split <- time.split[time.split != ""]
Cheers, Kai
P.S. great work! I love the comments in the source code ;)