Skip to content

Instantly share code, notes, and snippets.

@sckott
Created July 30, 2015 03:32
Show Gist options
  • Save sckott/547b68b011ccca627513 to your computer and use it in GitHub Desktop.
Save sckott/547b68b011ccca627513 to your computer and use it in GitHub Desktop.

The dataset in interest http://datamx.io/dataset/segurimty/resource/6145a539-cbde-4b0d-a3d3-d1a5eb013f5c

Load ckanr

library("ckanr")

Set base URL for the CKAN server

ckanr_setup(url = "http://datamx.io")

Get data for the resource

res <- resource_show(id = "6145a539-cbde-4b0d-a3d3-d1a5eb013f5c", as = "table")

Now we have the url for the dataset at http://datamx.io/dataset/9169cf41-a72c-412d-a48c-5aef12b5680a/resource/6145a539-cbde-4b0d-a3d3-d1a5eb013f5c/download/seguridadcic.csv to fetch the data. Let's use httr

library("httr")
out <- GET(res$url)
df <- content(out)
head(df)
##                    fecha           categoria
## 1 02/01/2014 03:41:17 AM SITUACION DE RIESGO
## 2 02/01/2014 03:01:36 AM SITUACION DE RIESGO
## 3 02/01/2014 02:30:21 AM            INCENDIO
## 4 02/01/2014 01:07:38 AM            INCENDIO
## 5 02/01/2014 01:00:28 AM            INCENDIO
## 6 02/01/2014 12:46:59 AM                ROBO
##                                                                                                                                                  titulo
## 1                          *SIT DE RIESGO* 1 persona falleciÃ\u0083³ y 1 herido por arma de fuego en ColÃ\u0083³n y JimÃ\u0083©nez, MTY -01.31@20:59
## 2                                    *SIT DE RIESGO* Por reporte de  personas baleadas en Colon y JimÃ\u0083©nez, precauciÃ\u0083³n MTY-01.31@20:59  
## 3                                                            *INCENDIO* De casa Juan Verazzano  y Rodrigo GalvÃ\u0083¡n Cumbres 5 sec MTY-01.31@20:27 
## 4                                           *INCENDIO* De Bodega En Rafael de la PeÃ\u0083±a entre Guerrero y Galeana Col. del Norte  MTY-01.31@19:05 
## 5                                                        *INCENDIO*  Patrulla quemÃ\u0083¡ndose en Av. Gomez Morin y Roberto Garza Sada SP-01.31@18:50
## 6 *ROBO A CASA* casa-habitaciÃ\u0083³n desde Diciembre, en calles Aluminio, Platino y Zinc Col RincÃ\u0083³n de San Miguel en Apodaca APO-01.31@18:36
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              contenido
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            *SIT DE RIESGO* por reporte de  personas baleadas en Colon y JimÃ\u0083©nez, precauciÃ\u0083³n MTY #mtyfollow 20:59 vÃ\u0083a @pelots82
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   *INCENDIO* de casa Juan Verazzano  y Rodrigo GalvÃ\u0083¡n Cumbres 5 sec MTY #mtyfollow 20:27 vÃ\u0083a @rocetre1
## 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               *INCENDIO* De Bodega En R.PeÃ\u0083±a y Galeana, Col.Del Nte MTY #mtyfollow 19:05 vÃ\u0083a @eroblesp
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
## 6  En Col RincÃ\u0083³n de San Miguel en Apodaca, de diciembre para acÃ\u0083¡ ha habido 3 robos pero el colmo fue ayer.\nAntier, el dia del hielo salimos a ver los carros y unos vecinos vieron a dos muchachos brincando la barda de una casa, los persiguieron pero no los alcanzaron.Y ayer los mismos dos muchachos se metieron a la misma casa, a las 3 de la tarde! Pero la seÃ\u0083±ora estaba adentro de la casa y grito y los ladrones se fueron.\nLas calles son Aluminio, Platino y Zinc. Algunos robos han sido cuando estÃ\u0083¡n solas las casas, El robo de la semana pasada fue como a las 5 de la maÃ\u0083±ana y habÃ\u0083a gente adentro pero dormida, se llevaron una tele. Y hace rato, como a las 5:30 estaba una camionetita de las de la panaderÃ\u0083a apodaca parada en la esquina y el chofer viendo para las calles. Me asome y lo vi y un poco despuÃ\u0083©s se fue.\n\nOjalÃ\u0083¡ manden vigilancia. APO
##                               ubicacion
## 1 (25.6859910943148, -100.315959267318)
## 2  (25.685933082431, -100.315005406737)
## 3 (25.7187729561128, -100.391018204391)
## 4 (25.7105010038621, -100.308367861435)
## 5 (25.6353359719803, -100.363415926695)
## 6 (25.7225522952971, -100.171260461211)
@Eflores89
Copy link

wow, thanks!

@sckott
Copy link
Author

sckott commented Jul 30, 2015

there's some issues with the encoding in some of the data there, but maybe it's fine on your machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment