From 27e80761f02d2f895047ee4c0e84d11f52dd5c8b Mon Sep 17 00:00:00 2001 From: jbedia Date: Tue, 18 Apr 2017 11:41:44 +0200 Subject: [PATCH] Bug fixes --- DESCRIPTION | 4 ++-- NEWS | 4 ++-- R/dataInventory.R | 9 ++++++--- R/loadStationData.R | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2857c10..aaaa092 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,8 +13,8 @@ Suggests: downscaleR Type: Package Title: R Package for Climate Data Loading and Manipulation -Version: 1.0.8 -Date: 2017-04-11 +Version: 1.0.9 +Date: 2017-04-18 Authors@R: as.person(c( "Santander Meteorology Group [aut]", "Joaquin Bedia [ctb,cre]", diff --git a/NEWS b/NEWS index e977ac8..04acb22 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ loadeR ====== -* Bug fix in dictionary parsing for single nc file datasets -* Removed RCurl dependency +* Bug fix in `loadStationData` +* Bug fix in stations data inventory * Other minor enhancements and documentation updates diff --git a/R/dataInventory.R b/R/dataInventory.R index a76c137..2aed0da 100644 --- a/R/dataInventory.R +++ b/R/dataInventory.R @@ -133,14 +133,17 @@ dataInventory.ASCII <- function(dataset, rs) { rm(list = c("lon", "lat")) other.metadata <- as.list(stations[ ,-pmatch(c("station_id", "longitude", "latitude"), names(stations))]) station.info <- list("station_id" = station_id, "LonLatCoords" = LonLatCoords, "times" = timeAxis, "other.metadata" = other.metadata) - rm(station_id, timeAxis, LonLatCoords, other.metadata) + station_id <- timeAxis <- LonLatCoords <- other.metadata <- NULL info <- list("Stations" = station.info, "Variables" = var.info, "Summary.stats" = NULL) if (isTRUE(rs)) { na.perc <- function(x) {round(length(which(is.na(x))) * 100 / length(x), 1)} aux.mat <- matrix(ncol = nrow(vars), nrow = length(station.info$station_id), dimnames = list(station.info$station_id, vars[ ,grep("variable", names(vars), ignore.case = TRUE)])) stats.list <- list("missing.percent" = aux.mat, "min" = aux.mat, "max" = aux.mat, "mean" = aux.mat) - for (i in 1:nrow(vars)) { - var <- read.csv(lf[grep(paste("^", var.info[i,1], "\\.*", sep = ""), list.files(dataset))], na.strings = var.info$missing.code[i])[ ,-1] + lf <- list.files(dataset) + lff <- list.files(dataset, full.names = TRUE) + for (i in 1:nrow(var.info)) { + varfile <- lff[grep(paste0("^", var.info[i,1], "\\."), lf)] + var <- read.csv(varfile, na.strings = var.info$missing.code[i])[ ,-1] stats.list[[1]][ ,i] <- apply(var, 2, na.perc) stats.list[[2]][ ,i] <- apply(var, 2, min, na.rm = TRUE) stats.list[[3]][ ,i] <- apply(var, 2, max, na.rm = TRUE) diff --git a/R/loadStationData.R b/R/loadStationData.R index 688d2d0..6c8cd96 100644 --- a/R/loadStationData.R +++ b/R/loadStationData.R @@ -150,7 +150,7 @@ loadStationData.ASCII <- function(dataset, var, stationID, lonLim, latLim, seaso stids <- stids[stInd] dimnames(coords) <- list(stids, c("longitude", "latitude")) ## Time dimension - fileInd <- grep(paste0("^", var, "\\.txt$"), dirContents) + fileInd <- grep(paste0(var, "\\.txt$"), dirContents) if (length(fileInd) == 0) { stop("[", Sys.time(),"] Variable requested not found", call. = FALSE) }