2018-06-07 00:13:15 +02:00
|
|
|
## ----setup, results='hide'-----------------------------------------------
|
|
|
|
# this vignette requires:
|
|
|
|
library(opensensmapr)
|
|
|
|
library(jsonlite)
|
|
|
|
library(readr)
|
|
|
|
|
2018-05-25 17:17:29 +02:00
|
|
|
## ----cache---------------------------------------------------------------
|
2018-06-07 00:13:15 +02:00
|
|
|
b = osem_boxes(grouptag = 'ifgi', cache = tempdir())
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
# the next identical request will hit the cache only!
|
2018-06-07 00:13:15 +02:00
|
|
|
b = osem_boxes(grouptag = 'ifgi', cache = tempdir())
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
# requests without the cache parameter will still be performed normally
|
2018-06-07 00:13:15 +02:00
|
|
|
b = osem_boxes(grouptag = 'ifgi')
|
|
|
|
|
|
|
|
## ----cachelisting--------------------------------------------------------
|
|
|
|
list.files(tempdir(), pattern = 'osemcache\\..*\\.rds')
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
## ----cache_custom--------------------------------------------------------
|
|
|
|
cacheDir = getwd() # current working directory
|
2018-06-07 00:13:15 +02:00
|
|
|
b = osem_boxes(grouptag = 'ifgi', cache = cacheDir)
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
# the next identical request will hit the cache only!
|
2018-06-07 00:13:15 +02:00
|
|
|
b = osem_boxes(grouptag = 'ifgi', cache = cacheDir)
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
## ----clearcache----------------------------------------------------------
|
|
|
|
osem_clear_cache() # clears default cache
|
|
|
|
osem_clear_cache(getwd()) # clears a custom cache
|
|
|
|
|
2018-06-07 00:13:15 +02:00
|
|
|
## ----data, results='hide'------------------------------------------------
|
2018-05-25 17:17:29 +02:00
|
|
|
# first get our example data:
|
2018-06-07 00:13:15 +02:00
|
|
|
measurements = osem_measurements('Windrichtung')
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
## ----serialize_json------------------------------------------------------
|
|
|
|
# serializing senseBoxes to JSON, and loading from file again:
|
2018-06-07 00:13:15 +02:00
|
|
|
write(jsonlite::serializeJSON(measurements), 'measurements.json')
|
|
|
|
measurements_from_file = jsonlite::unserializeJSON(readr::read_file('measurements.json'))
|
|
|
|
class(measurements_from_file)
|
2018-05-25 17:17:29 +02:00
|
|
|
|
|
|
|
## ----serialize_attrs-----------------------------------------------------
|
2018-06-07 00:13:15 +02:00
|
|
|
# note the toJSON call instead of serializeJSON
|
|
|
|
write(jsonlite::toJSON(measurements), 'measurements_bad.json')
|
|
|
|
measurements_without_attrs = jsonlite::fromJSON('measurements_bad.json')
|
|
|
|
class(measurements_without_attrs)
|
2018-05-25 17:17:29 +02:00
|
|
|
|
2018-06-07 00:13:15 +02:00
|
|
|
measurements_with_attrs = osem_as_measurements(measurements_without_attrs)
|
|
|
|
class(measurements_with_attrs)
|
2018-05-25 17:17:29 +02:00
|
|
|
|
2018-06-07 00:13:15 +02:00
|
|
|
## ----cleanup, include=FALSE----------------------------------------------
|
|
|
|
file.remove('measurements.json', 'measurements_bad.json')
|
2018-05-25 17:17:29 +02:00
|
|
|
|