Skip to contents

[Stable]

Usage

data_connection(
  open_fun = NULL,
  close_fun = NULL,
  ping_fun = NULL,
  if_conn_obj = FALSE
)

Arguments

open_fun

(CallableFunction) function to open connection

close_fun

(CallableFunction) function to close connection

ping_fun

(CallableFunction) function to ping connection

if_conn_obj

optional, (logical) whether to store conn object returned from opening

Value

TealDataConnection object

Examples

open_fun <- callable_function(data.frame) # define opening function
open_fun$set_args(list(x = 1:5)) # define fixed arguments to opening function

close_fun <- callable_function(sum) # define closing function
close_fun$set_args(list(x = 1:5)) # define fixed arguments to closing function

ping_fun <- callable_function(function() TRUE)

x <- data_connection( # define connection
  ping_fun = ping_fun, # define ping function
  open_fun = open_fun, # define opening function
  close_fun = close_fun # define closing function
)

x$set_open_args(args = list(y = letters[1:5])) # define additional arguments if necessary

x$open() # call opening function
x$get_open_call() # check reproducible R code
#> [1] "data.frame(x = 1:5, y = c(\"a\", \"b\", \"c\", \"d\", \"e\"))"

# get data from connection via TealDataConnector$get_dataset()
if (FALSE) {
x$open(args = list(x = 1:5, y = letters[1:5])) # able to call opening function with arguments
x$close() # call closing function
}