README.md

opendatarte

CRAN
status Lifecycle:
experimental

The goal of opendatarte is to help connect to https://data.rte-france.com and access data from its different resources API.

This package is in development.

Installation

The package is not on CRAN yet. You can installed the development version from GitHub with:

source("https://install-github.me/cderv/opendatarte")
# install.packages("remotes")
remotes::install_github("cderv/opendatarte")
# install.packages("devtools")
devtools::install_github("cderv/opendatarte")
pak::pkg_install("cderv/opendatarte")

How to use

Create an application and register some API

This package is useful to connect to your application on https://data.rte-france.com. Connect to the website, create an account and add an application. You can follow the help on the website.

Once your application is created you’ll get a client_id and a secret_id. You will need them to connect to your application form R using this package.

Configure R client to authenticate

library(opendatarte)

The main fonction is datarte_auth(). The simplest way to use it is to configure your R session with some environment variable containing your secrets: RTE_API_CLIENT and RTE_API_SECRET.

To configure them you can use usethis::edit_r_environ().

datarte_auth()

You can also provide client_id and secret_id as argument directly.

datarte_auth(client_id = "xxxxxxxxxx", client_secret = "xxxxxxxxxxxxxx")

or even, for advanced use, an httr token object directly in the token argument

datarte_auth(token = "a-stored-token.rds")

All this will do the same: It will configure you current R session so that the package opendatarte knows the credentials. You can then use the API using this package without no further authentication step.

This package is also compatible with the cache mechanism from httr. You can set cache = TRUE so that token is saved to disk and will be reused in future sessions, and not just the current session.

If you want to use httr directly and not this package for accessing the data, you can

my_token <- datarte_auth()
auth_rte <- httr::config(token = my_token)

You can put it any calls from httr like this

httr::GET("https://httpbin.org/get", auth_rte)

The authentication will be handle to access the data

datarte_auth()
httr::GET("https://httpbin.org/get", datarte_token())

Access data from the API using this package

There is some functions included in this package to be use with specific ressources. They aim at easing the use of the API by wrapping endpoints and query parameter.

They are all built on the same following concepts

# get data from the 
res <- RegistreAPI()
res <- RegistreAPI("ncc_less_100_mw")
res <- RegistreAPI("ncc_less_100_mw", sandbox = FALSE)
res <- RegistreAPI("ncc_less_100_mw", refresh = FALSE)

The results are currently of the following structure. It is a list with 3 elements

About available resources

All the ressources are not yet available in this package. The way to expose all the ressource is not clear yet and this could evolved.

Available ressource are :

Advanced Usage: Getting more resources

All the function are built upon call_api that can be used with any resource path for the api documentation.

res <- call_api("unavailability_additional_information/v1/sandbox/transmission_network_unavailabilities")

Main advantage is that it will return the same type of objects are previous functions and know how to use authentication.

You can also use httr directly by using the token datarte_token() in the call to the API. You can also use any other request package, you can get the current access token with get_current_token(TRUE) to be used with any tool you prefere, according the API documentation

In the future

Other related package

There is also the rte.data that will work to use the data.rte-france.com API



cderv/opendatarte documentation built on June 18, 2019, 6:41 p.m.