An R interface to InfluxDB 1.8.x time series databases.
influxr_connection
to be used for reading and writing from and to an influxDB database instanceinfluxr_select
influxr_write
influxr_select
influxr_query
On Ubuntu, you may need to install the following system packages
libssl-dev, libcurl4-openssl-dev
Nothing to do here.
Install required packages in R with
install.packages(c('data.table', 'xts', 'curl', 'httr', 'devtools'))
influxr
packageInstall the latest version of the influxr
package in R with
devtools::install_github("influxr/influxr")
Type one of the following in R
help(influxr)
?influxr
?influxr_connection
?influxr_select
?influxr_write
?influxr_query
?influxr_list_files
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)
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)
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)
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)
influxr_query
q <- influxr_query(client = tss_client, query = 'drop measurement test', database = 'db_test')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.