title: R fromJSON - $ operator is invalid for atomic vectors
body: <p>Why do I get this error below:</p>
  
  <pre><code>Error: $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>My dummy code for a simple test:</p>
  
  <pre><code>l &lt;- fromJSON('[{"winner":"68694999",  "votes":[
     {"ts":"Thu Mar 25 03:13:01 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}},
     {"ts":"Thu Mar 25 03:13:08 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}}],
    "lastVote":{"timestamp":1269486788526,"user":
     {"name":"Lamur","user_id":"68694999"}},"startPrice":0}]'
  )
  
  for(i in l) {
      print(i$votes)
  }
  </code></pre>
  
  <p>I just want to get the data off <code>votes</code></p>
  
  <p>Any ideas?</p>
  
  <p>This is my more complex json that I need to pull the data from:</p>
  
  <pre><code>json &lt;- '[{
      "data": {
          "dailysummary": [{
              "date": {
                  "pretty": "12:20 AM BST on June 28, 2017",
                  "year": "2017",
                  "mon": "06",
                  "mday": "28",
                  "hour": "00",
                  "min": "20",
                  "tzname": "Europe/London"
              },
              "fog": "0",
              "rain": "1",
              "snow": "0",
              "snowfallm": "",
              "snowfalli": "",
              "monthtodatesnowfallm": "",
              "monthtodatesnowfalli": "",
              "since1julsnowfallm": "",
              "since1julsnowfalli": "",
              "snowdepthm": "",
              "snowdepthi": "",
              "hail": "0",
              "thunder": "0",
              "tornado": "0",
              "meantempm": "16",
              "meantempi": "60",
              "meandewptm": "13",
              "meandewpti": "56",
              "meanpressurem": "997.19",
              "meanpressurei": "29.45",
              "meanwindspdm": "9",
              "meanwindspdi": "6",
              "meanwdire": "NW",
              "meanwdird": "326",
              "meanvism": "8.9",
              "meanvisi": "5.5",
              "humidity": "86",
              "maxtempm": "17",
              "maxtempi": "62",
              "mintempm": "14",
              "mintempi": "57",
              "maxhumidity": "100",
              "minhumidity": "77",
              "maxdewptm": "15",
              "maxdewpti": "59",
              "mindewptm": "10",
              "mindewpti": "50",
              "maxpressurem": "1001",
              "maxpressurei": "29.56",
              "minpressurem": "996",
              "minpressurei": "29.42",
              "maxwspdm": "18",
              "maxwspdi": "12",
              "minwspdm": "6",
              "minwspdi": "4",
              "maxvism": "10.0",
              "maxvisi": "6.2",
              "minvism": "4.5",
              "minvisi": "2.8",
              "gdegreedays": "10",
              "heatingdegreedays": "6",
              "coolingdegreedays": "0",
              "precipm": "0.0",
              "precipi": "0.00",
              "precipsource": "3Or6HourObs",
              "heatingdegreedaysnormal": "",
              "monthtodateheatingdegreedays": "",
              "monthtodateheatingdegreedaysnormal": "",
              "since1sepheatingdegreedays": "",
              "since1sepheatingdegreedaysnormal": "",
              "since1julheatingdegreedays": "",
              "since1julheatingdegreedaysnormal": "",
              "coolingdegreedaysnormal": "",
              "monthtodatecoolingdegreedays": "",
              "monthtodatecoolingdegreedaysnormal": "",
              "since1sepcoolingdegreedays": "",
              "since1sepcoolingdegreedaysnormal": "",
              "since1jancoolingdegreedays": "",
              "since1jancoolingdegreedaysnormal": ""
          }],
          "airport": "LCY"
      },
      "date": "2017-06-28"
  },{
      "data": {
          "dailysummary": [{
              "date": {
                  "pretty": "12:20 AM BST on June 29, 2017",
                  "year": "2017",
                  "mon": "06",
                  "mday": "29",
                  "hour": "00",
                  "min": "20",
                  "tzname": "Europe/London"
              },
              "fog": "0",
              "rain": "0",
              "snow": "0",
              "snowfallm": "",
              "snowfalli": "",
              "monthtodatesnowfallm": "",
              "monthtodatesnowfalli": "",
              "since1julsnowfallm": "",
              "since1julsnowfalli": "",
              "snowdepthm": "",
              "snowdepthi": "",
              "hail": "0",
              "thunder": "0",
              "tornado": "0",
              "meantempm": "16",
              "meantempi": "60",
              "meandewptm": "11",
              "meandewpti": "51",
              "meanpressurem": "995.85",
              "meanpressurei": "29.41",
              "meanwindspdm": "14",
              "meanwindspdi": "9",
              "meanwdire": "WSW",
              "meanwdird": "256",
              "meanvism": "10.0",
              "meanvisi": "6.2",
              "humidity": "71",
              "maxtempm": "18",
              "maxtempi": "64",
              "mintempm": "13",
              "mintempi": "55",
              "maxhumidity": "82",
              "minhumidity": "63",
              "maxdewptm": "11",
              "maxdewpti": "52",
              "mindewptm": "10",
              "mindewpti": "50",
              "maxpressurem": "999",
              "maxpressurei": "29.50",
              "minpressurem": "994",
              "minpressurei": "29.36",
              "maxwspdm": "24",
              "maxwspdi": "15",
              "minwspdm": "9",
              "minwspdi": "6",
              "maxvism": "10.0",
              "maxvisi": "6.2",
              "minvism": "10.0",
              "minvisi": "6.2",
              "gdegreedays": "10",
              "heatingdegreedays": "6",
              "coolingdegreedays": "0",
              "precipm": "0.0",
              "precipi": "0.00",
              "precipsource": "3Or6HourObs",
              "heatingdegreedaysnormal": "",
              "monthtodateheatingdegreedays": "",
              "monthtodateheatingdegreedaysnormal": "",
              "since1sepheatingdegreedays": "",
              "since1sepheatingdegreedaysnormal": "",
              "since1julheatingdegreedays": "",
              "since1julheatingdegreedaysnormal": "",
              "coolingdegreedaysnormal": "",
              "monthtodatecoolingdegreedays": "",
              "monthtodatecoolingdegreedaysnormal": "",
              "since1sepcoolingdegreedays": "",
              "since1sepcoolingdegreedaysnormal": "",
              "since1jancoolingdegreedays": "",
              "since1jancoolingdegreedaysnormal": ""
          }],
          "airport": "LCY"
      },
      "date": "2017-06-29"
  }]'
  
  l &lt;- fromJSON(json, ,flatten=TRUE)
  </code></pre>
  
  <p>I need to make it into a new dataframe:</p>
  
  <pre><code>airport key_date        ws      wd      tempi humidity
  LCY     2017-06-28      x       x       x       x
  LCY     2017-06-29      x       x       x       x
  </code></pre>
  
  <p>This is my old code but it does not work with this <code>l</code> dataframe from json anymore:</p>
  
  <pre><code># Initialize a data frame.
  weatherDf &lt;- data.frame()
  
  # Set key conditions for checking later.
  keyConditions &lt;- c("meanwindspdi", "meanwdird", "meantempm", "humidity")
  
  for(i in l) {
      # Get the airport code.
      airport &lt;- i$airport
  
      # Get the date.
      date &lt;- as.POSIXct(as.numeric(as.character(i$date))/1000, origin="1970-01-01", tz="UTC-1")
  
      # Get the data in dailysummary only.
      dailySummary &lt;- i$dailysummary
  
      # print(all(keyConditions %in% names(dailySummary)))
  
      # Make sure key conditions exist in dailySummary,
      # then use rbind or will get 'numbers of columns of arguments do not match'
      if (all(keyConditions %in% names(dailySummary))) {
          weatherDf &lt;- rbind(weatherDf, ldply(
              list(dailySummary),
              function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
          ))
      }
  }
  
  # Rename column names.
  colnames(weatherDf) &lt;- c("airport", "key_date", "ws", "wd", "tempi", 'humidity')
  
  # Convert certain columns weatherDf type to numberic.
  columns &lt;-c("ws", "wd", "tempi", "humidity")
  weatherDf[, columns] &lt;- lapply(columns, function(x) as.numeric(weatherDf[[x]]))
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>weatherDf &lt;- data.frame()
  for(i in 1:nrow(l)) {
      row &lt;- l[i,]
      # do stuff with row
  
      # Get the date.
      date &lt;- row$date
  
      # Get the airport code.
      airport &lt;- row$data.airport
      print(airport)
  
      # Get the data in dailysummary only.
      dailySummary &lt;- row$data.dailysummary
  
      # print(all(keyConditions %in% names(dailySummary)))
      weatherDf &lt;- rbind(weatherDf, ldply(
          list(dailySummary),
          function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
      ))
  }
  </code></pre>
  
  <p><strong>Edit 2:</strong></p>
  
  <pre><code>dailySummary &lt;- row$data.dailysummary
  print(names(dailySummary))
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>NULL
  </code></pre>
  
  <p>What I try to get:</p>
  
  <pre><code>[1] "fog"                                "rain"                               "snow"                              
   [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"              
   [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"                
  [10] "snowdepthm"                         "snowdepthi"                         "hail"                              
  [13] "thunder"                            "tornado"                            "meantempm"                         
  [16] "meantempi"                          "meandewptm"                         "meandewpti"                        
  [19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"                      
  [22] "meanwindspdi"                       "meanwdire"                          "meanwdird"                         
  [25] "meanvism"                           "meanvisi"                           "humidity"                          
  [28] "maxtempm"                           "maxtempi"                           "mintempm"                          
  [31] "mintempi"                           "maxhumidity"                        "minhumidity"                       
  [34] "maxdewptm"                          "maxdewpti"                          "mindewptm"                         
  [37] "mindewpti"                          "maxpressurem"                       "maxpressurei"                      
  [40] "minpressurem"                       "minpressurei"                       "maxwspdm"                          
  [43] "maxwspdi"                           "minwspdm"                           "minwspdi"                          
  [46] "maxvism"                            "maxvisi"                            "minvism"                           
  [49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"                 
  [52] "coolingdegreedays"                  "precipm"                            "precipi"                           
  [55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"      
  [58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"  
  [61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"           
  [64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"        
  [67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"  
  [70] "date.pretty"                        "date.year"                          "date.mon"                          
  [73] "date.mday"                          "date.hour"                          "date.min"                          
  [76] "date.tzname"                       
   [1] "fog"                                "rain"                               "snow"                              
   [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"              
   [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"                
  [10] "snowdepthm"                         "snowdepthi"                         "hail"                              
  [13] "thunder"                            "tornado"                            "meantempm"                         
  [16] "meantempi"                          "meandewptm"                         "meandewpti"                        
  [19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"                      
  [22] "meanwindspdi"                       "meanwdire"                          "meanwdird"                         
  [25] "meanvism"                           "meanvisi"                           "humidity"                          
  [28] "maxtempm"                           "maxtempi"                           "mintempm"                          
  [31] "mintempi"                           "maxhumidity"                        "minhumidity"                       
  [34] "maxdewptm"                          "maxdewpti"                          "mindewptm"                         
  [37] "mindewpti"                          "maxpressurem"                       "maxpressurei"                      
  [40] "minpressurem"                       "minpressurei"                       "maxwspdm"                          
  [43] "maxwspdi"                           "minwspdm"                           "minwspdi"                          
  [46] "maxvism"                            "maxvisi"                            "minvism"                           
  [49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"                 
  [52] "coolingdegreedays"                  "precipm"                            "precipi"                           
  [55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"      
  [58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"  
  [61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"           
  [64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"        
  [67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"  
  [70] "date.pretty"                        "date.year"                          "date.mon"                          
  [73] "date.mday"                          "date.hour"                          "date.min"                          
  [76] "date.tzname"   
  </code></pre>