{"id":20259925,"url":"https://github.com/influxdata/influxdb-client-r","last_synced_at":"2025-04-11T01:33:18.563Z","repository":{"id":48532230,"uuid":"373799860","full_name":"influxdata/influxdb-client-r","owner":"influxdata","description":"InfluxDB (v2+) Client R Package","archived":false,"fork":false,"pushed_at":"2022-10-26T09:37:13.000Z","size":451,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-24T22:42:08.563Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/influxdata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-04T10:05:22.000Z","updated_at":"2025-03-22T10:43:29.000Z","dependencies_parsed_at":"2022-09-16T23:20:36.642Z","dependency_job_id":null,"html_url":"https://github.com/influxdata/influxdb-client-r","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/influxdata","download_url":"https://codeload.github.com/influxdata/influxdb-client-r/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248325386,"owners_count":21084917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T11:17:17.231Z","updated_at":"2025-04-11T01:33:18.539Z","avatar_url":"https://github.com/influxdata.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# influxdb-client-r\n[![CircleCI](https://circleci.com/gh/influxdata/influxdb-client-r.svg?style=svg)](https://app.circleci.com/pipelines/github/influxdata/influxdb-client-r)\n[![codecov](https://codecov.io/gh/influxdata/influxdb-client-r/branch/master/graph/badge.svg)](https://app.codecov.io/gh/influxdata/influxdb-client-r)\n\nThis repository contains R package for InfluxDB 2.0 client.\n\n* [Features](#features)\n* [Installing](#installing)\n  * [Installing dependencies](#installing-dependencies)\n  * [Installing `influxdbclient` package](#installing-influxdbclient-package)\n* [Usage](#usage)\n  * [Client instantiation](#client-instantiation)\n  * [Querying data](#querying-data)\n    * [Type mapping](#incoming-type-mapping)\n    * [Time series](#using-retrieved-data-as-time-series)\n    * [Metadata](#querying-metadata)\n  * [Writing data](#writing-data)\n    * [Type mapping](#outgoing-type-mapping)\n    * [Output preview](#output-preview)\n    * [Write retrying](#write-retrying)\n  * [Getting status](#getting-status)\n    * [Health](#health-status)\n    * [Readiness](#readiness-status)\n  * [Advanced](#advanced)\n* [Known Issues](#known-issues)\n* [Contributing](#contributing)\n* [License](#license)\n\n## Features\n\nThe InfluxDB 2.0 client supports:\n\n- Querying data\n- Writing data\n- Getting status\n\n## Documentation\n\nThis section contains links to the client library documentation.\n\n* [Product documentation](https://docs.influxdata.com/influxdb/v2.0/api-guide/client-libraries/)\n* [Getting Started](#usage)\n* [Examples](#usage)\n* [API Reference](https://cran.r-project.org/package=influxdbclient/influxdbclient.pdf)\n* [Changelog](https://github.com/influxdata/influxdb-client-r/blob/master/CHANGELOG.md)\n\n## Installing\n\nThe package requires R \u003e= 3.4.\n\n### Installing dependencies\n\n```r\ninstall.packages(c(\"httr\", \"bit64\", \"nanotime\", \"plyr\"))\n```\n\n### Installing `influxdbclient` package  \n\nThe package is published on CRAN and can be installed with\n\n```r\ninstall.packages(\"influxdbclient\")\n```\n\nThe latest development version can be installed with\n\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"influxdata/influxdb-client-r\")\n```\n\n## Usage\n\n### Client instantiation\n\n```r\nlibrary(influxdbclient)\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\")\n```\n\n**Parameters**\n\n| Parameter | Description | Type | Default |\n|---|---|---|---|\n| `url` | InfluxDB instance URL | `character` | none |\n| `token` | authentication token | `character` | none |\n| `org` | organization name | `character` | none |\n\nHint: to avoid SSL certificate validation errors when accessing InfluxDB instance\nover https such as `SSL certificate problem: unable to get local issuer certificate`,\nyou can try to disable the validation using the following call before using any\n`InfluxDBClient` method. _Warning: it will disable peer certificate validation for the current R session._\n```r\nlibrary(httr)\nhttr::set_config(config(ssl_verifypeer = FALSE))\n```\n\n### Querying data\n\nUse `query` method.\n\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\")\n                            \ndata \u003c- client$query('from(bucket: \"my-bucket\") |\u003e range(start: -1h) |\u003e drop(columns: [\"_start\", \"_stop\"])')\ndata\n```\n\nFlux query can [yield](https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/outputs/yield/) multiple _results_ in one response, where each result may contain multiple tables.  \nReturn value is therefore a named list, where each element is a list of data frames that represent a _result_. Data frame represents Flux table. You can list the results using `names` method.\n\nQuite often, though, there is just a single result and therefore the `query` by default flattens the return value to simple unnamed list of data frames. This behaviour controlled by `flatSingleResult` parameter. With `flatSingleResult = FALSE`, you can check that the return value contains one element with name `\"_result\"` (default result name when there is no explicit `yield` in the query) and use the name to retrieve it, like\n\n```\n\u003e names(data)\n[1] \"_result\"\n\n\u003e data[[\"_result\"]]\n[[1]]\n                       time       name region sensor_id altitude grounded temperature\n1 2021-06-09T09:52:41+00:00 airSensors  south   TLM0101      549    FALSE  71.7844100\n2 2021-06-09T09:52:51+00:00 airSensors  south   TLM0101      547    FALSE  71.7684399\n3 2021-06-09T09:53:01+00:00 airSensors  south   TLM0101      563     TRUE  71.7819928\n4 2021-06-09T09:53:11+00:00 airSensors  south   TLM0101      560     TRUE  71.7487767\n5 2021-06-09T09:53:21+00:00 airSensors  south   TLM0101      544    FALSE  71.7335579\n```\n\n**Parameters**\n\n| Parameter | Description | Type | Default |\n|---|---|---|---|\n| `text` | Flux query | `character` | none |\n| `POSIXctCol` | Flux time to `POSIXct` column mapping | named `list` | `c(\"_time\"=\"time\")` |\n| `flatSingleResult` | Whether to return simple list when response contains only one result | logical | `TRUE` |\n\n#### Incoming type mapping\n\n| Flux type | R type |\n|---|---|\n| `string` | `character` |\n| `int` | `integer64` |\n| `float` | `numeric` |\n| `bool` | `logical` |\n| `time` | `nanotime` |\n\n#### Using retrieved data as time series\n\nFlux timestamps are parsed into `nanotime` (`integer64` underneath) type, because\nR datetime types do not support nanosecond precision. `nanotime` is not\na time-based object appropriate for creating a time series, though. By default,\n`query` coerces the `_time` column to `time` column of `POSIXct` type (see `POSIXctCol`\nparameter), with possible loss precision (which is unimportant in the context of R time series).\n\nSelect data of interest from the result like\n```r\n# from the first data frame, pick subset containing `time` and `_value` columns only\ndf1 \u003c- data[[1]][c(\"time\", \"_value\")]\n```\n\nThen, a time series object can be created from the data frame, eg. using `tsbox` package:\n```r\nts1 \u003c- ts_ts(ts_df(df1))\n```\n\nA data frame, or a time series object created from it, can be used for decomposition,\nanomaly detection etc, like\n```r\ndf1$`_value` %\u003e% ts(freq=168) %\u003e% stl(s.window=13) %\u003e% autoplot()\n```\nor\n```r\nts1 %\u003e% ts(freq=168) %\u003e% stl(s.window=13) %\u003e% autoplot()\n```\n\n#### Querying metadata\n\nFor queries returning records without time info (listing buckets, tag values etc.), set `POSIXctCol` to `NULL`.\n\n```r\nbuckets \u003c- client$query('buckets()', POSIXctCol = NULL)\n```\n\n### Writing data\n\nUse `write` method.\n\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\")\ndata \u003c- ...\nresponse \u003c- client$write(data, bucket = \"my-bucket\", precision = \"us\",\n                         measurementCol = \"name\",\n                         tagCols = c(\"region\", \"sensor_id\"),\n                         fieldCols = c(\"altitude\", \"temperature\"),\n                         timeCol = \"time\")\n```\n\nThe example is valid for `data.frame` `data` like the following:\n```\n\u003e print(data)\n                       time       name region sensor_id altitude grounded temperature\n1 2021-06-09T09:52:41+00:00 airSensors  south   TLM0101      549    FALSE  71.7844100\n2 2021-06-09T09:52:51+00:00 airSensors  south   TLM0101      547    FALSE  71.7684399\n3 2021-06-09T09:53:01+00:00 airSensors  south   TLM0101      563     TRUE  71.7819928\n4 2021-06-09T09:53:11+00:00 airSensors  south   TLM0101      560     TRUE  71.7487767\n5 2021-06-09T09:53:21+00:00 airSensors  south   TLM0101      544    FALSE  71.7335579\n\n\u003e str(data)\n'data.frame':\t5 obs. of  7 variables:\n $ time       :integer64 1623232361000000000 1623232371000000000 1623232381000000000 1623232391000000000 1623232401000000000\n $ name       : chr  \"airSensors\" \"airSensors\" \"airSensors\" \"airSensors\" ...\n $ region     : chr  \"south\" \"south\" \"south\" \"south\" ...\n $ sensor_id  : chr  \"TLM0101\" \"TLM0101\" \"TLM0101\" \"TLM0101\" ...\n $ altitude   :integer64 549 547 563 560 544\n $ grounded   : logi  FALSE FALSE TRUE TRUE FALSE\n $ temperature: num  71.8 71.8 71.8 71.7 71.7\n```\n\n**Parameters**\n\n| Parameter | Description | Type | Default |\n|---|---|---|---|\n| `x` | data  | `data.frame` (or list of) | none |\n| `bucket` | target bucket name | `character` | none |\n| `batchSize` | batch size | `numeric` | `5000` |\n| `precision` | timestamp precision | `character` (one of `s`, `ms`, `us`, `ns`) | `\"ns\"` |\n| `measurementCol` | measurement column name | `character` | `\"_measurement\"` |\n| `tagCols` | tags column names | `character` | `NULL` |\n| `fieldCols` | fields column names | `character` | `c(\"_field\"=\"_value\")` |\n| `timeCol` | time column name | `character` | `\"_time\"` |\n| `object` | output object | `character` | `NULL` |\n\nSupported time column value types: `nanotime`, `POSIXct`.\nTo write data points without timestamp, set `timeCol` to `NULL`.\nSee [Timestamp precision](https://docs.influxdata.com/influxdb/cloud/write-data/developer-tools/line-protocol/#timestamp-precision) for details.\n\nResponse is either `NULL` on success, or errorr otherwise.\n\nNote: default `fieldCols` value is suitable for writing back unpivoted data retrieved\nfrom  InfluxDB before. For usual tables (\"pivoted\" in Flux world), `fieldCols` should be\nunnamed list, eg. `c(\"humidity\", \"temperature\", ...)`.\n\n#### Outgoing type mapping\n\n| R type | InfluxDB type |\n|---|---|\n| `character` | `string` |\n| `integer`, `integer64` | `int` |\n| `numeric` | `float` |\n| `logical` | `bool` |\n| `nanotime`, `POSIXct` | `time` |\n\n#### Output preview\n\nTo preview how input data are serialized to InfluxDB [line protocol](https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/),\npass the name of object to receive the output as `object` parameter value.  \nIt changes `write` to dry-run operation (nothing is sent to the database).\nThe object will be assigned to the calling environment.  \n_This option is intended for debugging purposes._\n\n```r\ndata \u003c- ...\nresponse \u003c- client$write(data, bucket = \"my-bucket\", precision = \"us\",\n                         measurementCol = \"name\",\n                         tagCols = c(\"region\", \"sensor_id\"),\n                         fieldCols = c(\"altitude\", \"temperature\"),\n                         timeCol = \"time\",\n                         object = \"lp\")\nlp\n```\nSample output:\n```r\n\u003e print(lp)\n[[1]]\n[1] \"airSensors,region=south,sensor_id=TLM0101 altitude=549i,temperature=71.7844100 1623232361000000\"\n[2] \"airSensors,region=south,sensor_id=TLM0101 altitude=547i,temperature=71.7684399 1623232371000000\"\n[3] \"airSensors,region=south,sensor_id=TLM0101 altitude=563i,temperature=71.7819928 1623232381000000\"\n[4] \"airSensors,region=south,sensor_id=TLM0101 altitude=560i,temperature=71.7487767 1623232391000000\"\n[5] \"airSensors,region=south,sensor_id=TLM0101 altitude=544i,temperature=71.7335579 1623232401000000\"\n```\n\n#### Write retrying\n\nBy default, client will *not* retry failed writes. To instantiate a client with retry\nsupport, pass an instance of `RetryOptions`, eg:\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\",\n                             retryOptions = RetryOptions$new(maxAttempts = 3))\n```\nFor retry strategy with default options just pass `TRUE` as `retryOptions` parameter\nvalue:\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\",\n                             retryOptions = TRUE)\n```\n\nRetryable InfluxDB write errors are `429` and `503` status codes.\nThe retry strategy implements exponential backoff algorithm, customizable with\n`RetryOptions`.\n\n### Getting status\n\n#### Health status\n\nUse `health` method to get the health status.\n\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\")\n\ncheck \u003c- client$health()\n```\n\nResponse is list with health information elements (`name`, `status`, `version`,\n`commit`) or error.\n\n#### Readiness status\n\nUse `ready` method to get the readiness status.\n\n```r\nclient \u003c- InfluxDBClient$new(url = \"http://localhost:8086\",\n                             token = \"my-token\",\n                             org = \"my-org\")\n\ncheck \u003c- client$ready()\n```\n\nResponse is a list with status elements (`status`, `started`, `up`) or error.\n\n#### Advanced\n\nThe client automatically follows HTTP redirects.\n\nTo use the client with proxy, use `set_config` to configure the proxy:\n\n```r\nlibrary(httr)\nhttr::set_config(\n  use_proxy(url = \"my-proxy\", port = 8080, username = \"user\",password = \"password\")\n)\n```\n\n## Known Issues\n\n## Contributing\n\nContributions are most welcome. The fastest way to get something fixed is to open a PR.\n\n## License\n\nThe client is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfluxdata%2Finfluxdb-client-r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-r/lists"}