harphub / meteogrid

R package for working with gridded meteorological data
https://harphub.github.io/meteogrid/
Other
0 stars 6 forks source link

Fix proj4.str2list #1

Closed andrew-MET closed 4 years ago

andrew-MET commented 4 years ago

In situations where values in the proj4 string are in scientific format, e.g. "+proj=lcc +lat_0=63.3 +lon_0=15 +lat_1=63.3 +lat_2=63.3 +no_defs +R=6.371e+06" the value for R would be split at the "+". This PR ensures that the proj4 string is split at "+" followed by a letter.

Old version:

proj4.str2list( "+proj=lcc +lat_0=63.3 +lon_0=15 +lat_1=63.3 +lat_2=63.3 +no_defs +R=6.371e+06")
$proj
[1] "lcc"

$lat_0
[1] 63.3

$lon_0
[1] 15

$lat_1
[1] 63.3

$lat_2
[1] 63.3

$no_defs
[1] NA

$R
[1] 6.371

$`06`
[1] NA

New version:

proj4.str2list( "+proj=lcc +lat_0=63.3 +lon_0=15 +lat_1=63.3 +lat_2=63.3 +no_defs +R=6.371e+06")
$proj
[1] "lcc"

$lat_0
[1] 63.3

$lon_0
[1] 15

$lat_1
[1] 63.3

$lat_2
[1] 63.3

$no_defs
[1] NA

$R
[1] 6371000
adeckmyn commented 4 years ago

Alternatively, we can use a better strsplit command (+ must be preceded by spaces or start of string) p1 <- strsplit(pp,"[ ]+[+]|^[+]")[[1]][-1] # vector of "x=n" strings

andrew-MET commented 4 years ago

That's certainly more concise. I had trouble coming up with the regex to do that! I have updated the PR with that solution.