0

This is really strange but for some reason, I can't use dput with my dataframe.

When I run this:

df_reconstituted <- structure(list(region = c("alabama", "alaska", "arizona", "arkansas", 
"california", "colorado", "connecticut", "delaware", "district of columbia", 
"florida", "georgia", "hawaii", "idaho", "illinois", "indiana", 
"iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", 
"massachusetts", "michigan", "minnesota", "mississippi", "missouri", 
"montana", "nebraska", "nevada", "new hampshire", "new jersey", 
"new mexico", "new york", "north carolina", "north dakota", "ohio", 
"oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", 
"south dakota", "tennessee", "texas", "utah", "virginia", "washington", 
"west virginia", "wisconsin", "wyoming"), decade = c(1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980), value = c(628L, 92L, 1636L, 232L, 12690L, 
580L, 1070L, 28L, 460L, 6997L, 210L, 884L, 70L, 3276L, 1775L, 
186L, 250L, 1376L, 2273L, 350L, 921L, 1152L, 3848L, 704L, 502L, 
698L, 146L, 404L, 6678L, 94L, 11270L, 148L, 5957L, 484L, 158L, 
2474L, 1827L, 858L, 3942L, 284L, 1136L, 142L, 1817L, 6887L, 88L, 
1306L, 578L, 648L, 404L, 20L)), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -50L), .Names = c("region", 
"decade", "value"), vars = list(region))

I get:

`Error in structure(list(region = c("alabama", "alaska", "arizona", "arkansas",  : 
  object 'region' not found`

I can't imagine why. It looks like the column 'region' is included. My only thought is that perhaps it's an issue the the original df. I used a lot of dplyr on it, so maybe it is in some format that dput doesn't handle. It looks like this:

> str(df)
Classes ‘grouped_df’, ‘tbl_df’, ‘tbl’ and 'data.frame':  50 obs. of  3 variables:
 $ region: chr  "alabama" "alaska" "arizona" "arkansas" ...
 $ decade: num  1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
 $ value : int  628 92 1636 232 12690 580 1070 28 460 6997 ...
 - attr(*, "vars")=List of 1
  ..$ : symbol region  

Thanks for any advice.

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
  • You can convert to `data.frame` and use `dput` i.e. `dput(as.data.frame(df))` – akrun Feb 12 '16 at 07:25
  • This doesn't appear to be a duplicate. The question was the similar but the solution was different (akrun, your comment solved the problem..thanks!) – Monica Heddneck Feb 12 '16 at 07:43
  • This is the definition of a duplicate: similar question. –  Feb 12 '16 at 08:00
  • @MonicaHeddneck If you want to reopen, I can do it. – akrun Feb 12 '16 at 08:26
  • No, I'll take you guy's word for it...you know what you are doing much better than me. Thanks for your help. – Monica Heddneck Feb 12 '16 at 08:35
  • It is a duplicate. As in the answer at the other question, all that is needed to make this work is to change `vars = list(region)` to `vars = list(quote(region))`. The answer provided in the comment can be added as an answer to the other question either by you or @akrun, but the difference there is the assumption that you can go back to the original `data.frame`. My answer was directed at the scenario where you need to recreate the original data given the `dput`. As a method to save data, you would probably just want to use `save()`. Hope that makes sense. – A5C1D2H2I1M1N2O1R2T1 Feb 12 '16 at 15:13

0 Answers0