higgins at nceas.ucsb.edu
2006-Oct-10 20:28 UTC
[Rd] error in dput applied to dataframe (PR#9286)
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
ripley at stats.ox.ac.uk
2006-Oct-12 14:18 UTC
[Rd] error in dput applied to dataframe (PR#9286)
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 worksThere 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