Constructor function for creating a NiftiExtension-class object
with proper padding to ensure the size is a multiple of 16 bytes.
Arguments
- ecode
Integer extension code. See
NiftiExtensionCodesfor known codes. Common values: 4 (AFNI), 6 (comment), 32 (CIFTI).- data
The extension data. Can be:
A character string (will be converted to raw with null terminator)
A raw vector (used as-is)
Value
A NiftiExtension-class object.
Details
The function automatically handles padding to ensure the total extension size (esize) is a multiple of 16 bytes, as required by the NIfTI specification. The esize includes the 8-byte header (esize + ecode fields).
Examples
# Create a comment extension
ext <- NiftiExtension(ecode = 6L, data = "This is a comment")
ext@ecode
#> [1] 6
ext@esize
#> [1] 32
# Create an AFNI extension with XML data
afni_xml <- '<?xml version="1.0"?><AFNI_attributes></AFNI_attributes>'
afni_ext <- NiftiExtension(ecode = 4L, data = afni_xml)