Core+ R client
The R client allows you to:
- Create new workers.
- Interact with tables and objects on the server.
- Connect to existing Persistent Queries (PQs).
- Run queries server-side.
- And more.
The Core+ R client is built on top of the Community R client. This guide covers basic R client usage and troubleshooting. For a crash course in the R client, see Develop an R client query.
Test the installation
The following R code loads the client and connects to a running Deephaven Enterprise server. It then creates a temporary PQ with a simple query, and displays the resultant ticking table.
# These variables should be changed to match your server's configuration
# Note: The port number below is 8000 if your server uses envoy, and 8123 otherwise
base_dhe_url = "https://your-deephaven-server.com:8000/iris"
dhe_user = "username"
dhe_password = "password"
new_pq_name = "PqForRClientTest"
library("rdnd")
sm <- SessionManager$new(descriptive_name="Core+ session manager", source=paste0(base_dhe_url, "/connection.json"))
sm$password_authentication(dhe_user, dhe_password, dhe_user)
pq_config_builder <- sm$make_temp_pq_config_builder(new_pq_name)
pq_config_builder$set_max_heap_size_gb(4)
client <- sm$add_query_and_connect(pq_config_builder)
client$run_script("from deephaven import time_table; my_table = time_table(\"PT0.1S\")")
my_table = client$open_table("my_table")
Sys.sleep(2)
df = my_table$as_data_frame()
print(df)
Built-in R documentation
You can get more information about the Deephaven R client by consulting the built-in R documentation. In R, you can access the documentation for any function or package by using the ?
operator. To do this, simply type ?
followed by the name of the function or package you want to learn about.
You can try this:
library("rdnd")
library("rdeephaven")
?rdnd
?rdeephaven
?SessionManager
?PqConfigBuilder
?DndClient
?Client
?Table
Additionally, you can use the ls
method to list all the methods and fields on an object.
library("rdnd")
library("rdeephaven")
connection_json <- "https://host.mydomain.com:8000/iris/connection.json"
sm <- SessionManager$new(
descriptive_name=paste0("R session manager pid=", Sys.getpid()),
source=connection_json)
new_pq_name <- "my_new_pq"
pq_config_builder <- sm$make_temp_pq_config_builder(new_pq_name)
pq_config_builder$set_max_heap_size_gb(4);
pq_config_builder$set_script_code("python")
session <- sm$add_query_and_connect(pq_config_builder$build());
t <- session$historical_table("LearnDeephaven", "StockTrades")
ls(sm)
ls(pq_config_builder)
ls(session)
ls(t)
Troubleshooting
Logging
The R client uses the C++ implementation of gRPC to exchange messages with a Deephaven server. gRPC has an internal logging component that can be configured to log detailed information about connection state and messages exchanged between client and server to stderr. To enable detailed logging, set the GRPC_VERBOSITY
environment variable to DEBUG
before starting R:
export GRPC_VERBOSITY=DEBUG
Timeouts
During the creation of the SessionManager
object, three network connections are made in the order indicated below.
- Download the
connection.json
file from the provided URL. (This is a temporary connection that only lives while getting the file.) - Connect to the Deephaven Enterprise Authentication service.
- Connect to the Deephaven Enterprise Controller service.
The connections to Authentication and Controller are made based on the information downloaded from connection.json
. These two connections are maintained for as long as the SessionManager
object is valid.
All three operations must succeed for SessionManager
to be properly initialized or an error results. When experiencing connectivity issues, or if the information contained in the connection.json
file downloaded is wrong, you may see an error similar to:
Error: std::string deephaven_enterprise::utility::GetUrl(const string&)@/opt/deephaven/src/iris/DhcInDhe/cpp-client/utility/src/net.cc:121: Timeout was reached
Deephaven clients use gRPC, an open-source RPC framework from Google, to communicate with Deephaven servers. gRPC treats network errors as potentially temporary and uses a timeout model for network failures. This means that if the host address is incorrect or the server is down, the connection attempt does not fail immediately. Instead, gRPC keeps trying to connect, assuming that a new host name registration may appear or the server may restart and make the port available.
If the network issue is not resolved before the timeout window expires, the connection attempt fails and an error is returned.
Treating network connectivity issues as potentially temporary failures helps make the deployed infrastructure, clients, and servers more resilient. However, from a user's perspective, if there is a network failure, it may appear that the client is unresponsive for two minutes before an error occurs.
Important
The default timeout used by Deephaven in its clients is 2 minutes.
Tip
To help debug network and connectivity issues, set the GRPC_VERBOSITY
environment variable before starting an R session. The possible values are info
and debug
, with debug
providing more detailed, but noisier, output.
Setting GRPC_VERBOSITY
will print details of the gRPC
connection establishment, including SSL authentication and certificate validation, to the standard output.