EsgResult is a base class that represents basic query results from ESGF search RESTful API. It defines common fields and methods for results from all query types, including Dataset, File and Aggregation. Results from the three types are

In general, there is no need to create an EsgResult manually.

Author

Hongyuan Jia

Active bindings

id

A character vector indicating globally unique record identifiers.

url

A list of data.table with 3 columns:

  1. service \[character\]: The service types, e.g. OPENDAP, HTTPServer, etc.;

  2. url \[character\]: The actual URLs;

  3. mime_type \[character\]: The MIME types indicating the nature and format of the corresponding document of the URLs.

size

A vector of units indicating the file sizes.

fields

A character vector indicating all fields in the results, preserving the order returned by the response.

time_filter

A list describing the time range used by $filter_time(), or NULL if no result-level time filter has been recorded.

Methods


Method new()

Create a new EsgResult object

Usage

EsgResult$new(index_node, params, response, context = NULL)

Arguments

index_node

The URL to the ESGF Index Node. It should be the same as the index_node for an EsgQuery object that collects the query results.

params

A list of query parameters.

response

The result of an query response.

context

Optional saved-result context. Used internally for result-level metadata such as recorded time filters.

Returns

An EsgResult object.


Method to_data_table()

Convert the results into a data.table

Usage

EsgResult$to_data_table(fields = NULL, formatted = NULL)

Arguments

fields

A non-empty character vector indicating the fields to put into the data.table. If NULL, all fields in the query result will be used. Possible field names can be retrieved using $fields. Default: NULL.

formatted

Whether to use formatted values for special fields, including url and size. Default: FALSE.

Returns

A data.table.


Method to_dt()

Alias of $to_data_table().

Usage

EsgResult$to_dt(...)

Arguments

...

Arguments passed to $to_data_table().

Returns

A data.table.


Method count()

Count the number of matched records in current result

Usage

EsgResult$count()

Returns

An integer.


Method save()

Save the result into a JSON file

$save() puts main data of an EsgResult object into a JSON file which can be loaded to restore the current state of result using EsgResult$load().

Usage

EsgResult$save(file, pretty = TRUE)

Arguments

file

A string indicating the JSON file path to save the data to.

pretty

Whether to add indentation whitespace to JSON output. For details, please see jsonlite::toJSON(). Default: TRUE.

Returns

The full path of the output JSON file.


Method load()

Restore the result state from an JSON file

$load() reads data of an EsgResult object from a JSON file created using EsgResult$save(). Saved result fields are restored as read-only active bindings. A saved file can only be loaded by the matching result type.

Usage

EsgResult$load(file)

Arguments

file

A string indicating the JSON file path to read the data from.

Returns

The modified EsgResult object itself.


Method query_url()

Return the ESGF search query URL used to create this result.

Usage

EsgResult$query_url(pages = c("first", "all"))

Arguments

pages

Which recorded query URLs to return. "first" returns the first request URL. "all" returns every recorded request URL, including pagination requests. Default: "first".

Returns

A named character vector of query URLs.


Method reachable()

Probe whether result records are reachable through a service URL.

$reachable() performs a lightweight probe of the selected service URL for each record already held in the result. It returns diagnostic rows and does not modify result context or saved-result metadata.

Usage

EsgResult$reachable(
  service = "OPENDAP",
  level = c("data_node", "url"),
  probe = NULL
)

Arguments

service

ESGF URL service to probe. Default: "OPENDAP".

level

Probe level. "data_node" probes the root URL of each data node; "url" probes the actual service URL for each record. Default: "data_node".

probe

Optional named list of probe settings. Supported fields are timeout, concurrency, network_policy, cache_seconds, and cache_failures_seconds.

Returns

A data.table with columns record_index, id, data_node, service, url, reachable, latency_ms, error, probe_level, probe_url, and probe_cached.


Method slice()

Subset result records by row, logical selector, or record ID.

$slice() filters the records already held in memory. It does not change the original ESGF query parameters or query URL provenance.

Usage

EsgResult$slice(i = NULL)

Arguments

i

A positive or negative integer vector, logical vector, character vector of record IDs, or NULL. NULL returns an empty result.

Returns

A new result object of the same type.


Method filter()

Subset result records with a predicate function.

Usage

EsgResult$filter(predicate, formatted = FALSE)

Arguments

predicate

A function that accepts self$to_data_table() and returns a logical vector with one value per current record.

formatted

Whether to use formatted values when creating the predicate input data table. Default: FALSE.

Returns

A new result object of the same type.


Method selection()

Return local selection provenance for this result.

$selection() maps current rows back to the result object that first recorded selection provenance. It does not record intermediate filter steps.

Usage

EsgResult$selection()

Returns

A list with source_count, source_num_found, and source_indices.


Method clone()

The objects of this class are cloneable with this method.

Usage

EsgResult$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.