r6_storage_local: Local storage

r6_storage_localR Documentation

Local storage

Description

A local storage with flexible file format (default rds). The data format defines the data chunks per file.

Usage

storage_local_rds(name, format, path = NULL, read.only = TRUE)

storage_local_tsv(
  name,
  format,
  path = NULL,
  read.only = TRUE,
  tz = "Etc/GMT-1"
)

Arguments

name

name of the store

format

data format of the store

path

optional path to create the store under. Defaults to rappdirs::user_data_dir(appname = name, appauthor = "rOstluft")

read.only

read only store. disable put, if false and the store doesn't exist, the store will be initiated

tz

time zone for POSIXct's columns. Data is stored in UTC. Converted while reading. It is important, that the input data has the same time zone. Default "Etc/GMT-1"

Value

R6 class object of r6_storage_local

R6 class object of r6_storage_local

Fields

name

name of the store

format

data format of the store

path

root of the store

data_path

root of all chunks

content_path

path to the rds file containing statistics of store content

columns_path

path to the rds file containing the exact column types of the store content

meta_path

root of all meta files

read.only

flag for read.only usage of store. Default TRUE

ext

file extension for chunks. Default "rds"

read_function

function(file) for reading chunks from disk. Default base::readRDS()

write_function

function(object, file) for writing chunks to disk. Default base::saveRDS()

Methods

⁠$get(filter=NULL, ...)⁠ get data from the store. The name of the arguments depend on the format. The filter argument is applied to each chunk.

⁠$put(data)⁠ puts the data into the store. Stops if store is read only

⁠$get_content()⁠ returns a tibble with the amount of data points per chunk per series

⁠$list_chunks()⁠ get list of all chunks

⁠$get_meta(key=NULL)⁠ get meta data. If key is omitted returns all the content of all files in a named list of tibbles, with the file name without extension as name. If key is supplied as argument only the list contains only the specified key.

⁠$put_meta(...)⁠ puts meta data into the store. the name of the argument is used as file name and the value as data.

⁠$fix_content()⁠ generates the content file from the data files

⁠$destroy(confirmation)⁠ removes all files under path from the file system if "DELETE" is supplied as confirmation

Column Types

The first ⁠$put()⁠ saves the column types of the data in a file. All subsequents ⁠$put()⁠ calls must have the exact same column types: same order and classes of columns.

storage_local_tsv

This Storage is mainly for debugging purpose or sharing data with another scripting/programming language. Warning: Slow and doesn't support logical data type.

Examples

## init store, creates directory if necessary
format <- rOstluft::format_rolf()
store <- rOstluft::storage_local_rds("example_rOstluft", format, read.only = FALSE)

## read data from airmo export und put into the store
fn <- system.file("extdata", "Zch_Stampfenbachstrasse_2010-2014.csv",
                  package = "rOstluft.data", mustWork = TRUE)
df <- rOstluft::read_airmo_csv(fn)
store$put(df)

fn <- system.file("extdata", "Zch_Rosengartenstrasse_2010-2014.csv",
                  package = "rOstluft.data", mustWork = TRUE)
df <- rOstluft::read_airmo_csv(fn)
store$put(df)

## get all data min30 for 2011 and 2012
store$get(site = "Zch_Stampfenbachstrasse", interval = "min30", year = 2011:2012)

## get only data for O3
store$get(year = 2011:2012, site = "Zch_Stampfenbachstrasse", interval = "min30",
          filter = parameter == "O3")

## get NOx data from multiple stations
store$get(site = c("Zch_Stampfenbachstrasse", "Zch_Rosengartenstrasse"), interval = "min30",
          year = 2014, filter = parameter %in% c("NOx", "NO", "NO2"))

## get n data points grouped by intervall, station, parameter, year in the store
store$get_content()

## get list of all chunks
store$list_chunks()

## destroy store (careful removes all files on the disk)
store$destroy("DELETE")

## missing examples for meta functions


Ostluft/rOstluft documentation built on Feb. 6, 2024, 1:26 a.m.