[R] JSON data in data frame

William Dunlap wdunlap at tibco.com
Sat Jan 14 18:27:37 CET 2017


This is a question concerning the interface between the TIBCO products
Spotfire and TERR so most people on this mailing list won't have a
clue.  You will have better luck with TIBCO support or asking in the
Q&A section of https://community.tibco.com.

It does sound like you might have a data.frame nested within a
data.frame on the R/TERR side and Spotfire cannot deal with such a
structure - its data table columns must be simple vectors.  Try
unpacking the columns of the inner data frame and putting them one by
one into the outer one.

(I cannot say for sure because that URL gives me a 502 error.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Jan 14, 2017 at 1:25 AM, Archit Soni <soni.archit1989 at gmail.com> wrote:
> Hi Jermiah,
>
> When i ran this code in Spotfire, my aim is to get output as a data table.
> I am getting the same error:
>
> TIBCO Enterprise Runtime for R returned an error: 'Error in
> .cleanDataForExport(value, output.name) : Output data 'tab$coord' has
> illegal type: 'data.frame''.
>
>
> Code that I used:
>
> library(jsonlite)
>
> dat<- fromJSON('
> http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8
> ')
>
>
> tab <- dat$list
>
> tab is my output variable that will give me results in table format.
>
> Could you please suggest what we can do to resolve this error.
>
> Many Thanks,
> Archit
>
> On Fri, Jan 13, 2017 at 11:23 PM, jeremiah rounds <roundsjeremiah at gmail.com>
> wrote:
>
>> I TAd a course in R computing and the first thing I told students was
>> "inspect. inspect. inspect."
>> d1 <- fromJSON('http://api.openweathermap.org/data/2.5/
>> group?id=524901,703448,2643743&units=metric&appid=
>> ec0313a918fa729d4372555ada5fb1f8')
>> names(d1)
>> str(d1)
>> d1
>> d1$list
>> your_data = d1$list
>>
>> On Fri, Jan 13, 2017 at 1:12 AM, Archit Soni <soni.archit1989 at gmail.com>
>> wrote:
>>
>>> Hi All,
>>>
>>> Warm greetings, I am stuck at an issue to convert incoming json response
>>> to
>>> data frame.
>>>
>>> I am using below code to get the data
>>>
>>> library(jsonlite)
>>> d1 <- fromJSON('
>>> http://api.openweathermap.org/data/2.5/group?id=524901,70344
>>> 8,2643743&units=metric&appid=ec0313a918fa729d4372555ada5fb1f8
>>> ')
>>>
>>> d2 <- as.data.frame(d1)
>>>
>>> typeof(d2)
>>> list
>>>
>>> can you please guide me how can i get this data into pure data.frame
>>> format. The list in d1 has nested data.frame objects.
>>>
>>> Note: If you are unable to get data from api then can use below json
>>> string
>>> to test it out:
>>>
>>> JSON: {"cnt":3,"list":[{"coord":{"lon":37.62,"lat":55.75},"sys":{"
>>> type":1,"id":7323,"message":0.193,"country":"RU","sunrise":
>>> 1484286631,"sunset":1484313983},"weather":[{"id":600,"main":
>>> "Snow","description":"light
>>> snow","icon":"13d"}],"main":{"temp":-3.75,"pressure":1005,"h
>>> umidity":86,"temp_min":-4,"temp_max":-3},"visibility":8000,"
>>> wind":{"speed":4,"deg":170},"clouds":{"all":90},"dt":148429
>>> 0800,"id":524901,"name":"Moscow"},{"coord":{"lon":30.52
>>> ,"lat":50.43},"sys":{"type":1,"id":7358,"message":0.1885,"co
>>> untry":"UA","sunrise":1484286787,"sunset":1484317236},"
>>> weather":[{"id":804,"main":"Clouds","description":"overcast
>>> clouds","icon":"04d"}],"main":{"temp":-2,"pressure":1009,"hu
>>> midity":92,"temp_min":-2,"temp_max":-2},"visibility":9000,"
>>> wind":{"speed":4,"deg":250,"var_beg":210,"var_end":270},"
>>> clouds":{"all":90},"dt":1484290800,"id":703448,"name":"Kiev"
>>> },{"coord":{"lon":-0.13,"lat":51.51},"sys":{"type":1,"id":
>>> 5187,"message":0.1973,"country":"GB","sunrise":1484294413,"
>>> sunset":1484324321},"weather":[{"id":802,"main":"Clouds","de
>>> scription":"scattered
>>> clouds","icon":"03n"}],"main":{"temp":0.7,"pressure":1002,"t
>>> emp_min":0,"temp_max":2,"humidity":98},"visibility":10000,"
>>> wind":{"speed":6.2,"deg":270},"clouds":{"all":40},"dt":
>>> 1484290200,"id":2643743,"name":"London"}]}
>>>
>>> Any help is appreciated.
>>>
>>> --
>>> Regards
>>> Archit
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
>
> --
> Regards
> Archit
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list