eliocamp / metR

Tools for Easier Analysis of Meteorological Fields
https://eliocamp.github.io/metR/
142 stars 22 forks source link

ReadNetCDF Subsetting Fails #107

Closed m-saenger closed 4 years ago

m-saenger commented 4 years ago

Tried to extract data for multiple xy-locations based on the approach shown in the helpfile (second example for subsetting). However, function ReadNetCDF fails with an error. Thanks!

Reprex:

library(metR)
packageDescription("metR", fields = "Version")
#> [1] "0.5.0"

file <- system.file("extdata", "temperature.nc", package = "metR")

s = list(
  list(lat = -90:-70, lon = 0:60),
  list(lat = 70:90, lon = 300:360)
)

dt <- ReadNetCDF(file, subset = s)
#> Error in subset[[1]]: subscript out of bounds

Created on 2020-01-05 by the reprex package (v0.3.0)

eliocamp commented 4 years ago

Thanks! I've just fixed in the development version. You can install it with devtools::install_github("eliocamp/metR@dev").

As a workaround you can set the names of the elements of s thus:

library(metR)
packageDescription("metR", fields = "Version")
#> [1] "0.5.0"

file <- system.file("extdata", "temperature.nc", package = "metR")

s = list(
    list(lat = -90:-70, lon = 0:60),
    list(lat = 70:90, lon = 300:360)
)
names(s) <- c("", "")

dt <- ReadNetCDF(file, subset = s)

Created on 2020-01-05 by the reprex package (v0.3.0)