README.md

influxr

An R interface to InfluxDB 1.8.x time series databases.

Current features

Installation

Installing system dependencies

On Linux

On Ubuntu, you may need to install the following system packages

libssl-dev, libcurl4-openssl-dev

On Windows

Nothing to do here.

Installing R dependencies

Install required packages in R with

install.packages(c('data.table', 'xts', 'curl', 'httr', 'devtools'))

Installing the influxr package

Install the latest version of the influxr package in R with

devtools::install_github("influxr/influxr")

Getting help

Type one of the following in R

help(influxr)
?influxr
?influxr_connection
?influxr_select
?influxr_write
?influxr_query
?influxr_list_files

Examples

Create a connection object using influxr_connection to be used for reading and writing from and to an influxDB database instance

# Load the influxr package
library(influxr)

# Define a client to hold connection parameters to your server running the influxDB database instance. Here you can also provide username and password if authentication is needed.
tss_client <- influxr_connection(host = 'localhost', ssl = FALSE)

# Test the connection
ping(tss_client)

Reading from influxDB using influxr_select

# Let's get the following series 
# "fluxes,gasanalyzer=LI-6262,level=2,method=EC,software=Eddypro,sonic=Gill-R3,station=Hainich"

ec_fluxes <- influxr_select(
    tss_client,                         
      database = 'db_climate',          
      measurement = 'concentrations',
      fields = c('CO2', 'H2O', 'CH4'),
      from = '2019',
      to = '2019-12-31',
      tags = c(station = 'Hainich', level = 2),
      group_by = 'time(30m)',
      aggregation = 'mean',
      fill = 'none',
      verbose = TRUE
)

# Display the results
print(ec_fluxes)

Writing to influxDB using influxr_write

# Generate random data with different data types
# Number of data points to generate
n = 1e5

# Create dummy data.frame for uploading
  dummy_upload <-
    data.frame(
      time = Sys.time() + 1:n,
      Temp = round(rnorm(n) * 50, digits = 2),
      H = rnorm (n),
      DOY = floor(runif(n, 0, 365)),
      Code = replicate(n, paste0(sample(LETTERS, 4), collapse = ''))
    )


# Define meta data, knows as tags, for uploading to influxDB
  tags <-
    c(
      station = 'Hainich',
      instrument = 'uSonic-3',
      level = 1,
      empty_tag =''
    )


# Upload the data with the meta data
  res <- influxr_write(
    x = dummy_upload,
    client = tss_client,
    measurement = 'test',
    database = 'db_test',
    precision = 'ms',
    missing = c(NA, -9999),
    tags = tags,
    timestamp = 1, verbose = TRUE)


Getting data back using influxr_select

data_back <- influxr_select(tss_client, database = 'db_test', measurement = 'test', 
                            fields = c('Temp', 'H', 'DOY', 'Code'), aggregation = NULL,
                            verbose = T, limit = NULL)

Deleting data from the database using influxr_query

q <- influxr_query(client = tss_client, query = 'drop measurement test', database = 'db_test')


influxr/influxr documentation built on May 1, 2024, 2:07 a.m.