Next: , Previous: Sinks, Up: Specifics


3.5 Character Encoding

The R API for chacter re-encoding is covered in the Writing R Extensions manual. However, several connection types (i.e. file, fifo, pipe, gzfile, bzfile, xzfile, and clipboard) have a special mechanism for interacting with the character re-encoding subsystem. These connection types set the fgetc method in the struct Rconn structure to a “dummy” function named dummy_fgetc. The purpose of this function is to buffer, re-encode, and return characters read using the fgetc_internal method. Hence, the fgetc_internal method performs the connection-specific work, returning a single byte (char) read from the connection. Several connections that support character re-encoding additionally set the vsprintf member of struct Rconn to dummy_vsprintf. This function simultaneously performs the function typically associated with vsprintf (variable argument conversion and printing according to a format string), as well as character re-encoding. This “dummy” mechanism is generic, as evidenced by its use in a variety of connection types, and provides one of the most powerful connection features.