From ripley at stats.ox.ac.uk  Thu Oct 12 16:18:45 2006
From: ripley at stats.ox.ac.uk (ripley at stats.ox.ac.uk)
Date: Thu, 12 Oct 2006 16:18:45 +0200 (CEST)
Subject: [Rd] error in dput applied to dataframe (PR#9286)
Message-ID: <20061012141845.CC93E4C934@slim.kubism.ku.dk>

The help for dput says

      Deparsing an object is difficult, and not always possible.  With
      the default 'control = c("showAttributes")', 'dput()' attempts to
      deparse in a way that is readable, but for more complex or unusual
      objects, not likely to be parsed as identical to the original.
      Use 'control = "all"'  for the most complete deparsing; use
      'control = NULL' for the simplest deparsing, not even including
      attributes.

You needed to take note of that:

> dput(df, control="all")
structure(list(aaa = structure(as.integer(c(1, 2, 1)), .Label = c("AAA",
"BBB"), class = "factor"), bbb = c(1, 2, 3)), .Names = c("aaa",
"bbb"), row.names = as.integer(c(NA, 3)), class = "data.frame")

dump() would have worked correctly.

On Tue, 10 Oct 2006, higgins at nceas.ucsb.edu wrote:

> Full_Name: Daniel F Higgins
> Version: 2.4.0
> OS: Windows XP and Mac OSX
> Submission from: (NULL) (128.111.242.49)
>
>
> Create a dataframe as indicated below and apply 'dput' to it; note that the
> row.names attribute is incorrect!
>
>> aaa <- c("AAA","BBB","AAA")
>> bbb <- c(1,2,3)
>> df <- data.frame(aaa,bbb)
>> dput(df)
> structure(list(aaa = structure(c(1, 2, 1), .Label = c("AAA",
> "BBB"), class = "factor"), bbb = c(1, 2, 3)), .Names = c("aaa",
> "bbb"), row.names = c(NA, 3), class = "data.frame")
>> dput(df,file="puttest.R")
>> dget("puttest.R")
> Error in attributes(.Data) <- c(attributes(.Data), attrib) :
>        row names must be 'character' or 'integer', not 'double'
>>
>
> However, if R version 2.3 is used, the value for row.names is:
> row.names = c("1", "2", "3")
> and the dget command then works

There was no 'R version 2.3': please see the posting guide.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




[Rd] error in dput applied to dataframe (PR#9286)
ripley at stats.ox.ac.uk