influxr_write: Write data to InfluxDB database

Description Usage Arguments Details Value See Also

View source: R/write.R

Description

influxr_write writes a 'data.frame' to influxDB databases.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
influxr_write(
  client,
  x,
  measurement,
  database,
  precision = c("ms", "u", "ns", "s", "m", "h"),
  tags = NULL,
  timestamp,
  timestamp_format = NULL,
  timestamp_offset = 0,
  tz = ifelse(Sys.getenv("TZ") != "", Sys.getenv("TZ"), Sys.timezone()),
  missing = c(NA, Inf),
  from = NULL,
  to = NULL,
  inclusive = FALSE,
  exclude_timestamp_cols = TRUE,
  ...
)

Arguments

x

A 'data.frame' that contains the data to be written to the influxDB database.

precision

precision of the timestamp. Default to milliseconds 'ms'.

tags

A named character vector of tag keys and values 'c(tag_key=tag_value)' pairs to be applied to the uploaded data. Must not contain single quotes or double quotes. See Details on how to escape special characters and on how unescaped special characters are checked for. example ‘tags=(station=’Hainich', level = 3)'

timestamp

The timestamp of the data. Can be one of the following:

  • A numeric vector specifying the column(s) of the provided data in which the timestamp is contained either in POSIXt format, or as a character string which is converted to POSIXt format according to timestamp_format, using tz as the timezone. If several character columns are specified, their contents in each row are pasted together, separated by a single whitespace.

  • A character vector which is converted to POSIXt format according to timestamp_format, using tz as the timezone.

  • A POSIXt vector. It will be used as is without conversion or changing the timezone.

  • A function in this case x will be passed to the provided function to extract the timestamp vector.

timestamp_format

character string. Format for converting timestamp from character to POSIXt format. Check the strptime function from base R for more information about formatting.

timestamp_offset

Number of seconds to apply as an offset to the timestamp and file modification times before uploading to database.

tz

character. Timezone of the data. Will be used in converting timestamp from character to POSIXt format. The default is environment variable "TZ" otherwise system timezone Sys.timezone().

You can specify other timezones, e.g. for time in Germany, do tz = "Etc/GMT-1". Please note the sign of the offset, which might be counter intuitive: if you are east of Greenwich you have to give a negative offset because you have to decrease your local time to make it become UTC time. For timezones west of Greenwich the offset is positive.

missing

A vector of missing values to be replaced with NULL when uploaded to InfluxDB default to 'c(NA, Inf)'.

from

Timestamp in POSIXt format specifying the lower limit ("greater or equal to", i.e. inclusive) of timestamps to upload to database. Note: timestamps in data to upload have to be in ascending order for the detection to work.

to

Timestamp in POSIXt format specifying the upper limit ("smaller than", i.e. exclusive) of timestamps to upload to database. Note: timestamps in data to upload have to be in ascending order for the detection to work.

inclusive

logical. Whether the upper time limit be interpreted inclusively or not.

exclude_timestamp_cols

logical. Whether the column(s) specified in timestamp be excluded from dataframe before upload.

Details

Influx Line Protocol prohibits quoting of measurements, tag keys, tag values and field keys. Special characters can nonetheless be escaped with a backslash.

Please note that in R you need to escape the backslash character itself with another backslash character when constructing strings. Function writeLines may be useful when trying to figure out which characters of a string have not been properly escaped.

Value

TRUE if upload is successful.

See Also

strptime for converting character strings to POSIXt format.

OlsonNames for valid time zone names.


influxr/influxr documentation built on Aug. 5, 2020, 9:03 p.m.