Paste your Google Webmaster Tools verification code here


We have created the R library BcnDataAccess. The purpose of this package is to make the import of data about Barcelona really simple and easily extensible by anyone inside  R.  It is still in a very early version, so we would be very grateful if you give us feedback about it.


To install the package you need devtools,


How to use it

The set of data sources is organized as a tree, where the root is BcnDataSources. To explore the branches, write
and press TAB. Each branch contains other branches or a set of data sources, for instance:

# Source:

The branches may contain data sources. You can get the info

# Source:
# Description: Dades demografiques de les seccions censals de la ciutat de Barcelona.
# Last update: 25/10/2013

The main functions of a data source are openSource that opens the corresponding webpage (in case the data comes from a webpage) and getData that returns a data.frame


Extending the tree

To build a new branch use the function addInformationBranch with the name of the branch and the source webpage (if any).

BcnDataSources$addInformationBranch( 'MyBranch', '' )

To build a new data source connection use the function addInformationSource, as in the following example:

  newName = 'VotsBarris',
  getDataFunction = function(){
    data(votsBarris, envir = environment())
  description = "Vots per Barris",
  lastUpdate = "October 2014",
  broughtBy = "Josep Marc Mingot"

  • The main element is the getDatafunction that has to return a data.frame. It may also have parameters and get data from a webpage, data base or any others.
  • The newName argument is the name that will appear in the BcnDataSources> tree.
  • The \
    dataSource, in case it is a webpage, will be opened by the openSourcePage function.
  • description, lastUpdate, broughtBy are informative fields, where lastUpdate is the last time the information was updated and broughtBy concerns who has built this particular leave.
  • fieldDescription is a matrix where the rows are the fields of the data.frame given by the getDatafunction.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Barcelona Data Lovers