From savicky at cs.cas.cz  Fri Mar 12 08:28:29 2010
From: savicky at cs.cas.cz (Petr Savicky)
Date: Fri, 12 Mar 2010 08:28:29 +0100
Subject: [Rd] Associative array?
In-Reply-To: <20100311180909.76c938cc.misc7@emerose.org>
References: <20100311075212.66a6a0e7.misc7@emerose.org>
	<85602218-8121-4893-A262-86EC56E75002@r-project.org>
	<20100311180909.76c938cc.misc7@emerose.org>
Message-ID: <20100312072829.GB30541@cs.cas.cz>

On Thu, Mar 11, 2010 at 06:09:09PM -0600, Ben wrote:
[...]
> > I don't quite understand - characters are (after raw vectors) the
> > most expressive data type, so I'm not quite sure why that would be a
> > limitation .. You can cast anything (but raw vector with nulls) into
> > to a character.
> 
> It's no big problem, it's just that if the solution is to convert to
> character type, then there are some implementation details to worry
> about.  For instance, I assume that as.character(x) is a reversible
> 1-1 mapping if x is an integer (and not NA or NULL, etc).  But
> apparently that isn't exactly true for floats, and it would get more
> complicated for other data types.

Let me add a comment on the question of an invertible conversion of double
values to character type. The function as.character() intentionally does
not keep the exact value and performs some rounding. However, conversion
of a double x to character type, which preserves the number exactly, may
be obtained, for example, using
  formatC(x, digits=17, width=-1)

Petr Savicky.



[Rd] Associative array?
Petr Savicky