# R List Object Serialization

> Use when after extracting structured metadata (e.g., instrument parameters, scan counts, time ranges) from Thermo Fisher Scientific .

- Skill: `holobiomicslab/r-list-object-serialization` (Agent Skill)
- Install (CLI): `npx skillmds@latest add holobiomicslab/r-list-object-serialization`
- Raw SKILL.md: https://api.skillmd.com/api/skills/holobiomicslab/r-list-object-serialization/raw
- Safety review: PASS (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: CC-BY-4.0
- Author: HolobiomicsLab (https://skillmd.com/u/holobiomicslab)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/holobiomicslab/r-list-object-serialization

---


# R List Object Serialization

## Summary

Convert R list objects extracted from binary proteomics data files into JSON format for portability, validation, and downstream integration. This skill bridges in-memory R data structures with file-based interchange formats, enabling modular end-to-end analysis pipeline development.

## When to use

Apply this skill after extracting structured metadata (e.g., instrument parameters, scan counts, time ranges) from Thermo Fisher Scientific .raw files via readFileHeader() or similar list-returning functions, and you need to persist, validate, or hand off that metadata to non-R tools or external pipelines without losing structure.

## When NOT to use

- Input is already a JSON string or file — serialize only R objects, not data already in interchange format.
- Metadata is small enough to embed directly in R scripts or configuration files — serialization adds overhead when direct in-memory passing suffices.
- Downstream tools require binary or columnar formats (e.g., NetCDF, HDF5) for performance — JSON is text-based and may not scale for large spectral datasets.

## Inputs

- R list object (e.g., returned by readFileHeader())
- list object containing instrument metadata (instrument model, file name, time range, scan count, software version)

## Outputs

- JSON file (.json extension)
- Validated JSON string with all list keys and values intact

## How to apply

After calling readFileHeader() or another rawrr function that returns an R list object containing dynamically-generated metadata items, serialize the list to JSON format using rjson::toJSON(). Write the serialized output to a file with .json extension. Verify the output file exists and parse it back into R or another language to confirm valid JSON structure and that all expected keys (instrument model, file name, time range, number of scans, etc.) are preserved without data loss or type corruption. This approach is necessary because the extracted metadata varies by instrument model and control software version, making JSON a flexible interchange format that documents the actual schema discovered at runtime.

## Related tools

- **rjson** (R package for serializing R objects to JSON format)
- **readFileHeader()** (rawrr function that extracts file header metadata as an R list from Thermo .raw files) — https://github.com/fgcz/rawrr
- **rawrr** (R package wrapping RawFileReader .NET assembly to read Thermo Fisher Scientific .raw files and return structured R objects) — https://github.com/fgcz/rawrr

## Examples

```
H <- rawrr::readFileHeader('autoQC01.raw'); json_str <- rjson::toJSON(H); writeLines(json_str, 'autoQC01_header.json'); parsed <- rjson::fromJSON(file='autoQC01_header.json'); identical(names(H), names(parsed))
```

## Evaluation signals

- Output .json file exists and is readable as text.
- JSON is valid (parseable by rjson::fromJSON() or another JSON parser without syntax errors).
- All keys from the original R list appear in the JSON object with no omissions.
- Data types are correctly preserved (strings, integers, arrays, nested objects) after round-trip serialization and deserialization.
- Instrument-specific metadata fields (instrument model, software version) are present and match the values in the original R list object.

## Limitations

- JSON serialization does not preserve R-specific attributes (e.g., class, factors, custom object metadata) — only basic types (list, vector, string, number, logical).
- Dynamically-generated metadata fields vary by instrument model and control software version, so JSON schemas cannot be fixed a priori; validation must be schema-agnostic or schema-discovery-based.
- Large nested list structures or high-dimensional arrays may produce verbose or inefficient JSON; consider compression or column-based formats (Parquet, HDF5) for big proteomics datasets.
- JSON does not natively support complex number types or missing value markers (NA) in R; these must be encoded as strings or null, requiring custom parsing on deserialization.

## Evidence

- [methods] List object serialization for metadata interchange: "readFileHeader() retrieves metadata from binary raw files including instrument model, file name, time range of data acquisition, and number of scans, returning these items as a list object containing"
- [other] JSON serialization workflow with rjson: "Call readFileHeader() to extract the file header as an R list object. 3. Serialize the list to JSON format using rjson::toJSON. 4. Write the serialized JSON to an output file with .json extension. 5."
- [results] Metadata variability by instrument version: "The respective function is called `readFileHeader()` and returns a simple `R` object of type `list`"
- [methods] File I/O for data extraction and return to R: "Extracted information is written to a temporary location on the harddrive, read back into memory and parsed into R objects"

