Statis...actory(3pm)

✨ NAME ✨

Statistics::R::IO::REXPFactory β€” bestie, this is the module with all the functions for parsing R data files πŸ’… it's giving parser factory realness


πŸŽ€ VERSION πŸŽ€

version 1.0002 β€” yes she's got a number, and no she will not be elaborating 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole vibe in code form, no cap:

use Statistics::R::IO::REXPFactory qw( unserialize );

# Assume $data was created by reading, say, an RDS file
my ($rexp, $state) = @{unserialize($data)}
    or die "couldn't parse";

# If we're reading an RDS file, there should be no data left
# unparsed
die 'Unread data remaining in the RDS file' unless $state->eof;

# the result of the unserialization is a REXP
say $rexp;

# REXPs can be converted to the closest native Perl data type
print $rexp->to_pl;

like… look at her go 😭✨


πŸ’– DESCRIPTION πŸ’–

This module is the one doing the actual reading of serialized R objects and turning them into a Statistics::R::REXP. Lowkey you're not supposed to use it directly though β€” it's normally wrapped up all cozy by readRDS in Statistics::R::IO and readRData in Statistics::R::IO. So like, it's the backstage crew, not the main character 🫢


🌈 SUBROUTINES 🌈

  • unserialize $data β€” builds a Statistics::R::REXP object out of its serialization in $data. Hands you back a pair: the object itself, plus the Statistics::R::IO::ParserState sitting at the end of serialization. iconic duo honestly πŸ‘‘
  • intsxp, langsxp, lglsxp, listsxp, rawsxp, realsxp, refsxp, strsxp, symsxp, vecsxp, envsxp, charsxp, cplxsxp, closxp, expsxp, s4sxp β€” these are the parsers for the corresponding R SEXP-types. one for each, she's thorough πŸ’…
  • object_content β€” parses object info and its data by sequencing unpack_object_info and then object_data. two-step slay ✨
  • unpack_object_info β€” parser for the serialized object info structure. Returns a hash with the keys is_object, has_attributes, has_tag, object_type, and levels, each one matching the field in R serialization described at <http://cran.r-project.org/doc/manuals/r-release/R-ints.html#Serialization-Formats>. There's also an extra key flags holding the full 32-bit value exactly as stored in the file πŸ”₯
  • object_data $obj_info β€” parser for a serialized R object. It peeks at the object_type key in the $obj_info hash so it knows which parser to bring out for that particular type. vibe check passed βœ…
  • vector_and_attributes $object_info, $element_parser, $rexp_class β€” the convenience parser for vectors πŸŽ€ vectors get serialized with a SEXP for the vector elements first, then attributes stored as a tagged pairlist. Attributes only get stored if $object_info says they're present, and the vector elements get parsed using $element_parser. Then the parsed attributes and elements get handed over as arguments to the constructor of $rexp_class, which should be a subclass of Statistics::R::REXP::Vector. teamwork makes the dream work 🫢
  • header β€” parser for the header of R serialization: the serialization format (XDR, binary, etc.), the version number of the serialization (currently 2), and two 32-bit integers saying which version of R wrote the file, followed by the minimal version of R needed to read the format. receipts on receipts πŸ“‹
  • xdr, bin β€” parsers for the RDS header that tell you whether the file is in XDR or native-binary format. pick your fighter πŸ’€
  • maybe_long_length β€” parser for vector length, and she's flexible because she allows for the encoding of 64-bit long vectors that got introduced in R 3.0. growth mindset πŸ’œ
  • tagged_pairlist_to_rexp_hash β€” converts a pairlist into a REXP hash whose keys are the pairlist's element tags and whose values are the pairlist elements themselves. glow up ✨
  • tagged_pairlist_to_attribute_hash β€” converts object attributes (which get serialized as a pairlist with the attribute name living in the element's tag) into a hash you can use as the attributes argument to Statistics::R::REXP constructors.

Some attributes come serialized using a compact encoding β€” for instance, when a table's row names are just integers 1:nrows β€” and this function will decode them into a complete REXP. expanding the abbreviation, we love to see it πŸ’…


πŸ’€ BUGS AND LIMITATIONS πŸ’€

There are no known bugs in this module. periodt. ✨ For bug reporting though, please go see Statistics::R::IO. she handles the complaints department πŸ™ˆ


🌸 SUPPORT 🌸

See Statistics::R::IO for support and contact information 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Davor Cubranic <cubranic@stat.ubc.ca> β€” thank you for your service bestie πŸ’–


This software is Copyright (c) 2017 by University of British Columbia.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007

and that's the whole page, bestie 🧚 this was perl v5.34.0, dated 2022-02-10, straight out of the User Contributed Perl Documentation collection β€” mwah, take care of her πŸ’œβ­