Skip to content

"NA" vs. NA

6 messages · (Ted Harding), Duncan Murdoch, Adrian Dusa +1 more

#
Dear All,

I assume this is an R-devel issue, apologies if I missed something
obvious. I have a dataframe where the row names are country codes,
based on ISO 3166, something like this:

------------
"v1"    "v2"
"UK"    1    2
"NA"    2    3
------------

It happens that "NA" is the country code for "Namibia", and that
creates problems on using this data within a package due to this:

Error in read.table(zfile, header = TRUE, as.is = FALSE) :
  missing values in 'row.names' are not allowed

I realise that NA is reserved in R, but I assumed that when quoted it
would be usable.
For the moment I simply changes the country code, but I wonder if
there's any (other) solution to circumvent this issue.

Thanks very much in advance,
Adrian
#
On 05-Apr-2012 11:03:15 Adrian Dusa wrote:
Hi Adrian,
The default in read.table() for the "na.strings" parameter is

  na.strings = "NA"

So, provided you have no "NA" in the data portion of your file
(or e.g. any missing values are simply blank) you could use
something like:

read.table(zfile, header = TRUE, as.is = FALSE, na.strings="OOPS")

which should avoid the problem.

Hoping this helps,
Ted.

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 05-Apr-2012  Time: 12:21:57
This message was sent by XFMail
#
Hi Ted,
On Thu, Apr 5, 2012 at 14:22, Ted Harding <Ted.Harding at wlandres.net> wrote:
Sure, that solves the problem on reading the data from R, but the
point was it "creates problems on using this data within a package".

The error is thrown by:
R CMD check --as-cran /path/to/my/package

(and I have no direct control over it...)

Best,
Adrian
#
On 12-04-05 7:27 AM, Adrian Dusa wrote:
You still haven't explained what you are doing to cause the problem, so 
I'll guess that you have this file in your data directory of the 
package, in tab-delimited form.

Just store it in some other form, e.g. as a binary object to be loaded.

Duncan Murdoch
#
On Thu, Apr 5, 2012 at 14:49, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
Indeed, this is exactly what I did (tab-delimited file in the data
directory) and yes, this solves the issue.
Thanks very much,
Adrian
#
Change the "na.strings" argument to read.table or read.csv when reading 
in the file.  By default, na.strings="NA".  If you do something like

countryCodes <- read.csv("mySourceFile.csv", na.strings="")

then your problem will go away.
On 4/5/2012 7:26 AM, Adrian Dusa wrote: