| Title: | SafeInsights Fusion SDK |
|---|---|
| Description: | Researcher-facing client for the SafeInsights Enclave Fusion Framework. A destination-side analysis calls fusion_request() on a peer handle; a source-side container registers Data-Partner-approved operation handlers and calls fusion_serve(). The package drives the per-job Fusion Tunnel App's enclave-local API (submit/poll, duplicate suppression, single in-flight round per peer, typed errors, budget hints) and owns the language-neutral fusion envelope shared with the Python package. |
| Authors: | SafeInsights [aut, cre, cph] |
| Maintainer: | SafeInsights <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.3.0 |
| Built: | 2026-10-07 22:23:29 UTC |
| Source: | https://github.com/safeinsights/fusion-sdk |
Decode a fusion table into a data frame
fusion_as_data_frame(x)fusion_as_data_frame(x)
x |
A |
A data frame with typed columns: string to character, integer to integer (double
when a value exceeds the 32-bit range), integer64 to character, number to double,
boolean to logical, date to Date, datetime to UTC POSIXct. null becomes NA.
The column types travel as attr(, "fusion_types").
Last budget hint seen on a peer
fusion_budget(peer)fusion_budget(peer)
peer |
A |
A fusion_budget (rounds and bytes used vs. max) or NULL before the first response.
Every leg is attempted. Legs that already ended report their terminal code.
fusion_complete(fusion)fusion_complete(fusion)
fusion |
A |
A named character vector of per-leg outcomes: "OK", a terminal code, or "ERROR".
If any leg failed with a non-terminal error, that error is raised after all legs were tried.
Reads the environment contract (FUSION_ROLE, FUSION_TUNNEL_ENDPOINT(S),
FUSION_TUNNEL_TOKEN(S)), waits for every leg to reach CHANNEL_UP, and returns a handle
whose peers are keyed by the peer organization slug reported by each tunnel.
fusion_connect( env = Sys.getenv(), settings = NULL, ready_timeout = NULL, transports = NULL )fusion_connect( env = Sys.getenv(), settings = NULL, ready_timeout = NULL, transports = NULL )
env |
Environment variables; defaults to |
settings |
A |
ready_timeout |
Seconds to wait for |
transports |
Advanced: a named list of transports to use instead of the environment (the simulator and tests). |
An object of class fusion.
/v1/info
Content-free: prints labels, hosts, leg ids, peer slugs, roles, states and API versions; never a token. Used by the Docker smoke and by researchers debugging a container.
fusion_doctor(env = Sys.getenv(), wait = FALSE, json = FALSE)fusion_doctor(env = Sys.getenv(), wait = FALSE, json = FALSE)
env |
Environment variables; defaults to |
wait |
If |
json |
If |
TRUE when every tunnel is reachable, has the expected role and a compatible API
(and is CHANNEL_UP when wait = TRUE); FALSE otherwise. Invisible.
Is this condition terminal for its peer?
fusion_is_terminal(e)fusion_is_terminal(e)
e |
A condition object. |
TRUE for fusion_config_error, fusion_not_ready_error, fusion_limit_exceeded_error
and fusion_session_error; FALSE otherwise.
By default the SDK writes one message() per event to stderr. Tests and embedding
applications can capture the lines instead.
fusion_log_sink(sink = NULL)fusion_log_sink(sink = NULL)
sink |
A function of one character argument, or |
The previous sink, invisibly.
Declare an operation handler
fusion_operation( handler, person_id_param = NULL, cardinality = "aggregate", count_column = NULL, sanitize = FALSE )fusion_operation( handler, person_id_param = NULL, cardinality = "aggregate", count_column = NULL, sanitize = FALSE )
handler |
A function |
person_id_param |
Name of the parameter whose distinct values |
cardinality |
One of |
count_column |
For |
sanitize |
If |
An object of class fusion_operation.
Build the operation registry
fusion_operations(...)fusion_operations(...)
... |
Named |
An object of class fusion_operations.
Get a peer handle
fusion_peer(fusion, name = NULL)fusion_peer(fusion, name = NULL)
fusion |
A |
name |
The peer organization slug. With one leg it may be omitted. |
A fusion_peer handle for fusion_request().
List peers
fusion_peers(fusion)fusion_peers(fusion)
fusion |
A |
A data frame with columns peer, legId, direction, state.
Blocks until the source's response arrives, a typed error is raised, or the round timeout
(with the SDK's same-correlationId re-issues) is exhausted. Researcher code never sees a
correlationId or a retransmission.
fusion_request(peer, operation, params = list(), timeout = NULL)fusion_request(peer, operation, params = list(), timeout = NULL)
peer |
A |
operation |
The Data-Partner-approved operation name. |
params |
A named list of parameters. Use |
timeout |
Per-attempt round timeout in seconds (default |
A fusion_response with $body (raw JSON as nested lists), $budget, $operation,
$peer, $correlation_id, $message_id, $bytes, $duration_s. Decode a table body with
fusion_as_data_frame().
Blocks. Returns invisibly on STUDY_COMPLETE; signals fusion_limit_exceeded_error /
fusion_session_error on a terminal error and fusion_config_error on a misconfigured
environment or registry. A source serves exactly one tunnel. Source scripts should do nothing
but fusion_serve() after setup: the long-poll loop blocks the R process by design.
fusion_serve( operations, env = Sys.getenv(), settings = NULL, ready_timeout = NULL, transport = NULL )fusion_serve( operations, env = Sys.getenv(), settings = NULL, ready_timeout = NULL, transport = NULL )
operations |
A |
env |
Environment variables; defaults to |
settings |
A |
ready_timeout |
Seconds to wait for |
transport |
Advanced: a transport to use instead of the environment (simulator, tests). |
NULL, invisibly.
Reads the FUSION_* knobs from an environment (default: the process environment). Every
default is provisional until load-tested with the real tunnel.
fusion_settings(env = Sys.getenv())fusion_settings(env = Sys.getenv())
env |
A named character vector of environment variables; defaults to |
A list of class fusion_settings.
fusion_simulate()
Rounds are numbered from 1 per peer, as in the fake tunnel scenarios.
fusion_sim_faults( drop_response_rounds = integer(0), error_after_round = NULL, max_rounds = NULL, max_response_bytes_per_round = NULL )fusion_sim_faults( drop_response_rounds = integer(0), error_after_round = NULL, max_rounds = NULL, max_response_bytes_per_round = NULL )
drop_response_rounds |
Rounds whose response is withheld until the SDK re-issues the same
|
error_after_round |
The leg becomes |
max_rounds |
Cap on rounds enforced by the simulated source tunnel ( |
max_response_bytes_per_round |
Cap on response bytes per round ( |
An object of class fusion_sim_faults.
Wires a source handler set and a destination analysis function together through an in-process transport, so researchers can develop and test fusion code against sample data in the IDE. The same guards, memo, error envelopes and typed errors apply as in a real study.
fusion_simulate( operations, analysis, guards = NULL, caps = NULL, approved_operations = NULL, faults = NULL, settings = NULL )fusion_simulate( operations, analysis, guards = NULL, caps = NULL, approved_operations = NULL, faults = NULL, settings = NULL )
operations |
A |
analysis |
A function of one argument, the connected |
guards |
Optional list like |
caps |
Optional caps object as |
approved_operations |
Optional approved operation list for the registry pre-flight. |
faults |
A |
settings |
A |
Whatever analysis returns. Every leg is closed on a clean return.
Column types are inferred from the R classes (character/factor to string, integer to
integer, double to number, logical to boolean, Date to date, POSIXct to
datetime, bit64::integer64 to integer64) unless overridden with types. NA, NaN
and infinities encode as null.
fusion_table(df, types = NULL)fusion_table(df, types = NULL)
df |
A data frame (or tibble). |
types |
Optional named character vector of column types, e.g. |
An object of class fusion_table, accepted as a handler return value or a body.