Search code examples
rr-markdownjsonliterjson

Why can't I download from a link in R markdown?


I tried to run this code in a rmd file but still I'm getting an error and I don't know how to resolve this. The Code is: pizza3 <- fromJSON('http://www.jaredlander.com/data/PizzaFavorites.json')

And I'm getting an error as:

Error in fromJSON("http://www.jaredlander.com/data/PizzaFavorites.json") :
unexpected character 'h' Calls: <Anonymous> ... withCallingHandlers ->
withVisible -> eval -> eval -> fromJSON```


Solution

  • @Rohit this works for me, maybe you haven't loaded jsonlite as Stéphane has suggested.

    library(jsonlite)
    pizza3 <- jsonlite::fromJSON("http://www.jaredlander.com/data/PizzaFavorites.json")
    pizza3
    #>                     Name                                Details
    #> 1          Di Fara Pizza     1424 Avenue J, Brooklyn, NY, 11230
    #> 2          Fiore's Pizza   165 Bleecker St, New York, NY, 10012
    #> 3              Juliana's  19 Old Fulton St, Brooklyn, NY, 11201
    #> 4     Keste Pizza & Vino   271 Bleecker St, New York, NY, 10014
    #> 5  L & B Spumoni Gardens      2725 86th St, Brooklyn, NY, 11223
    #> 6 New York Pizza Suprema       413 8th Ave, New York, NY, 10001
    #> 7           Paulie Gee's 60 Greenpoint Ave, Brooklyn, NY, 11222
    #> 8                Ribalta      48 E 12th St, New York, NY, 10003
    #> 9              Totonno's  1524 Neptune Ave, Brooklyn, NY, 11224
    

    Created on 2020-02-28 by the reprex package (v0.3.0)