Skip to content

Commit

Permalink
Switch from RJSONIO to jsonlite
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRoth committed Mar 10, 2017
1 parent 0bf6178 commit 3e8d6a3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Imports:
data.table,
xts,
foreach,
RJSONIO,
jsonlite,
rgdal,
sp,
ncdf4,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import(foreach)
import(futile.logger)
import(rgdal)
import(sp)
importFrom(RJSONIO,fromJSON)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,'%>%')
importFrom(methods,as)
importFrom(methods,extends)
Expand Down
8 changes: 3 additions & 5 deletions R/ImportData.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ HomogenPrecipDates <- function(period) {
#' @param path for saving data (if set to NULL data are always downloaded but not saved)
#' @return data.table with rows being the single events
#' @export
#' @import data.table
#' @importFrom RJSONIO fromJSON
#' @examples
#' data <- Earthquakes("induced", Groningen, "1990/2016")
#' Description(data)
Expand All @@ -121,9 +119,9 @@ Earthquakes <- function(type="induced", area = NULL, period = NULL, path = "") {

EarthquakesDownload <- function(type, area, period, call) {
DownloadMessage("Earthquakes")
URL <- SpecifyUrlEarthquakes(type)
rawJson <- RJSONIO::fromJSON(URL)
tmp <- data.table::rbindlist(lapply(rawJson$events, GetJsonValues))
URL <- SpecifyUrlEarthquakes(type)
jsonTable <- jsonlite::fromJSON(URL)$events
tmp <- UpdateJsonTable(jsonTable)
if (!is.null(area)) tmp <- ClipQuakes(tmp, area)
if (!is.null(period)) tmp <- tmp[date %in% HomogenPrecipDates(period),]
KnmiData(tmp, call, "Earthquakes")
Expand Down
25 changes: 10 additions & 15 deletions R/TechnicalImport.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ ReadZippedFile <- function(url, colNames) {
return(data)
}

GetJsonValues <- function(entry) {
date <- as.Date(entry["date"], tz="CET")
time <- as.character(entry["time"])
# datetime <- as.POSIXlt(paste0(date, " ", time))
type <- as.character(entry["type"])
depth <- as.numeric(entry["depth"])
evaluationMode <- as.character(entry["evaluationMode"])
lat <- as.numeric(entry["lat"])
lon <- as.numeric(entry["lon"])
mag <- as.numeric(entry["mag"])
place <- as.character(entry["place"])
return(data.frame(date, time,
place, type,
evaluationMode, lat, lon, depth, mag,
stringsAsFactors = FALSE))
UpdateJsonTable <- function(jsonTable) {
tmp <- as.data.table(jsonTable)
tmp[, date := as.Date(date, tz = "CET")]
tmp[, depth := as.numeric(depth)]
tmp[, lat := as.numeric(lat)]
tmp[, lon := as.numeric(lon)]
tmp[, mag := as.numeric(mag)]
setcolorder(tmp, c("date", "time", "place", "type",
"evaluationMode", "lat", "lon", "depth", "mag"))
tmp
}
1 change: 1 addition & 0 deletions R/imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#' @importFrom xts .parseISO8601
#' @importFrom stringr str_replace_all
#' @importFrom magrittr '%>%'
#' @importFrom jsonlite fromJSON
#' @import sp
NULL

0 comments on commit 3e8d6a3

Please sign in to comment.