Skip to contents

This class implements the common features of objects that make up Zarr. This class is the ancestor of zarr_node and thus the zarr_group and zarr_array classes. This class manages common features such as names and attribute management. This class may also be used by other descendant classes that need a name and attributes (such as the coordinate system classes in package geozarr).

The main function of this class is to manage attributes of a Zarr object. Groups and arrays can have attributes, but other object descending from this class may have attributes as well. In order to accommodate the various applications, all methods dealing with attributes take a list object with the attributes as the first argument - the class has no private or public field to hold the attributes.

This class should never have to be instantiated or accessed directly. Instead, use instances of zarr_group or zarr_array. Function arguments are largely not checked, the group and array instances should do so prior to calling methods here. The big exception is checking the validity of node names.

Active bindings

name

Set or retrieve the name of the Zarr object.

Methods


zarr_object$new()

Initialize a new Zarr object.

Usage

zarr_object$new(name)

Arguments

name

The name of the node.


zarr_object$print_attributes()

Print attributes to the console. Usually called by the zarr_group and zarr_array print() methods.

Usage

zarr_object$print_attributes(
  dirty = FALSE,
  max_attributes = Zarr.options$max_attributes,
  root = "",
  ...
)

Arguments

dirty

Optional. Logical flag that indicates if the attributes have unsaved edits. Default is FALSE.

max_attributes

Optional. The maximum number of attribute entries to print at each level of the attribute hierarchy. The default is the value of the max_attributes option, see zarr_options(). Use Inf to print all entries.

root

Optional. The name (path) of the attribute to print, with everything below it, using / as separator for nested attributes and 1-based indices for array elements, as in the attribute() method. The default "" prints all attributes.

...

Ignored.

Details

An attribute entry is a member of a JSON object or an item of a JSON array of objects; an array of scalar values is a single entry. The limit of max_attributes applies to each level of the attribute hierarchy separately: of every object and of every array of objects only the first max_attributes entries are printed, followed by the number of entries at that level that were not printed.

Nothing is printed when root does not identify an existing attribute.

Returns

Nothing. The attributes of the Zarr object are printed to the console.


zarr_object$attribute()

Retrieve a specific attribute by path.

Usage

zarr_object$attribute(atts, name)

Arguments

atts

The list object with the attributes.

name

The name (path) of the attribute to retrieve, using / as separator for nested attributes. Numeric path segments index into array attributes (1-based), e.g. "zarr_conventions/2/name" retrieves the name field of the second convention object.

Returns

The attribute value, or NULL if not found.


zarr_object$set_attribute()

Add an attribute to the metadata of the object. If an attribute name already exists, it will be overwritten.

Usage

zarr_object$set_attribute(atts, name, value)

Arguments

atts

The list object with the attributes.

name

The name of the attribute. The name may be a compound path, relative to the "attributes" entry in the metadata, using a slash "/" as path separator. Each of the elements in the path (between slashes) must begin with a letter and be composed of letters, digits, and underscores and can be at most 255 characters long. Missing path elements will be created.

value

The value of the attribute. This can be of any supported type, including a vector or list of values. In general, an attribute should be a character value, a numeric value, a logical value, or a short vector or list of any of these.

Returns

A list with the updated attributes.


zarr_object$append_array_attribute()

Append an attribute to an array in the metadata of the object. If an attribute name already exists, it will be overwritten.

Usage

zarr_object$append_array_attribute(atts, name, value, after = NULL)

Arguments

atts

The list object with the attributes.

name

The name of the attribute. The name may be a compound path, relative to the "attributes" entry in the metadata, using a slash "/" as path separator. Each of the elements in the path (between slashes) must begin with a letter and be composed of letters, digits, and underscores and can be at most 255 characters long. Missing path elements will be created.

value

The value of the attribute. This can be of any supported type, including a vector or list of values. In general, an attribute should be a character value, a numeric value, a logical value, or a short vector or list of any of these.

after

A subscript, after which value is to be appended. The default is NULL, meaning that value will be placed after the existing values. Specifying after = 0L will place value before the existing values.

Returns

A list with the updated attributes.


zarr_object$delete_attribute()

Delete an attribute or array element. If the attribute is not present, this method simply returns.

Usage

zarr_object$delete_attribute(atts, name)

Arguments

atts

The list object with the attributes.

name

Character. The name (path) of the attribute to delete, using / as separator for nested attributes, e.g. "first/second/my_att". The name is relative to the attributes entry in the metadata of the node. To target an element of a JSON array attribute, append the 1-based index as the path segment, e.g. "first/second/my_arr/2" to delete the second element in the array, or "first/second/my_arr/2/description" to delete only the description field inside it. This nesting can be arbitrarily deep, including over multiple JSON arrays.

Returns

A list with the updated attributes.


zarr_object$clone()

The objects of this class are cloneable with this method.

Usage

zarr_object$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.